I am having a hard time with a question from this week's assignment. I am supposed to write pseudo-code for an everyday task, which I will write below:

Design
Main Module
Call Open Door Module
Call Ignition Module
Call Reverse Module
Call Pull Out Module
End Main Module

Open Door Module
Has Key Been Entered Into Key Slot
If Yes Then Unlock Car Door
If No Remain Locked
Has Door Handle Opened
If Yes Then Open Door
If No Than Keep Door Closed
Close Open Door Module

Ignition Module
Has Key Been Entered Into Ignition
If Yes Then Start Car
If No Keep Car Engine Off
Close Ignition Module

Reverse Module
Has Driver Engaged Seatbelt
If Yes Then Proceed
If No Then Engage Seatbelt Signal
Has Driver Checked Mirrors
If Yes Then Proceed To Reversing
If No Then Remain In Park
End Reverse Module

Pull Out Module
Is Street Clear
If Yes Then Proceed To Pull Out
If No Then Wait For Street to Clear
End Pull out Module


Below, is the question:

• Identify how you can encapsulate the data and processes you identified into an object-oriented design.


I don't know what they mean by encapsulating the data from the driving the car code into an object oriented design. How would I go about this?

Thanks for any help!

Get started with you HW
Post your progress and a specific question
If you just post the question that you got for an assignment without showing your efforts then you will be ignored

commented: seems like a perfectly reasonable question to me. -1

I don't know what they mean by encapsulating the data from the driving the car code into an object oriented design.

I don't either. The question seems like B.S. to me. If they want to teach object oriented concepts they should do it with real examples and with real programs. Go to your university and demand a refund.

I don't either. The question seems like B.S. to me. If they want to teach object oriented concepts they should do it with real examples and with real programs. Go to your university and demand a refund.

Thanks for the response...I probably should as much as they are charging!

Get started with you HW
Post your progress and a specific question
If you just post the question that you got for an assignment without showing your efforts then you will be ignored

I did post my progress. The entire pseudo-code and some other information that I didn't post (due to non-relevance to the question) was my progress. I just don't understand data encapsulation. I was seeking some help from professionals so that I can get a better grasp on it, that's all.

Not looking for a handout, just some help in understanding a concept, that's all.

http://www.cs.mun.ca/~donald/bsc/node13.html

I agree with Rashakil that it is difficult to convey the concept without simply writing a real program. Here is a situation that might make sense as far as why data encapsulation is useful. Lets say you want to put the car in reverse, so you have a variable called 'gear'. Since you might want certain things to be true (i.e., car cannot be moving) before you can change the gear to Reverse, you can't give the programmer direct access to your 'gear' variable. So you hide the gear variable from them, not allowing them to access it directly. Rather, you provide a module/method that allows them to put the Car in Reverse. So all they need to do is call the Reverse module which will indirectly make sure the car is not already moving, then change the gear to reverse, then make sure the driver has looked, etc. Had you allowed the programmer direct access to the 'gear' variable, they might have changed it in a way that you did not want: for example, they might have put the gear in reverse while the Car was still moving. By not allowing them to access the 'gear' variable, you are encapsulating your data - you are controlling the ways that it can be accessed. Now let's say later on your requirements for "being in reverse" change. Let's say you now want everyone's seat-belt to be fastened before allowing the person to go in Reverse. By not allowing the programmer access to the 'gear', and by forcing them to use the Reverse module instead, you are making it so that you can make changes to the Reverse module without changing the interface the person needs to use.

http://www.cs.mun.ca/~donald/bsc/node13.html

I agree with Rashakil that it is difficult to convey the concept without simply writing a real program. Here is a situation that might make sense as far as why data encapsulation is useful. Lets say you want to put the car in reverse, so you have a variable called 'gear'. Since you might want certain things to be true (i.e., car cannot be moving) before you can change the gear to Reverse, you can't give the programmer direct access to your 'gear' variable. So you hide the gear variable from them, not allowing them to access it directly. Rather, you provide a module/method that allows them to put the Car in Reverse. So all they need to do is call the Reverse module which will indirectly make sure the car is not already moving, then change the gear to reverse, then make sure the driver has looked, etc. Had you allowed the programmer direct access to the 'gear' variable, they might have changed it in a way that you did not want: for example, they might have put the gear in reverse while the Car was still moving. By not allowing them to access the 'gear' variable, you are encapsulating your data - you are controlling the ways that it can be accessed. Now let's say later on your requirements for "being in reverse" change. Let's say you now want everyone's seat-belt to be fastened before allowing the person to go in Reverse. By not allowing the programmer access to the 'gear', and by forcing them to use the Reverse module instead, you are making it so that you can make changes to the Reverse module without changing the interface the person needs to use.

So does data encapsulation involve object-oriented processes, as it makes the user go through the "object" to successfully use the program? When you say that the programmer "encapsulates" the data by making sure specific criteria is met in order to initiate a module, you are saying the module is the object, and the program is oriented by the module?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.