bg287

CS361 Notes

Posted in cs361 by bnmng on 2012 08/30

C++ Not completely OO, but “Object Centered”.

When defining class, consider necessary attributes.  Like for a class representing a car, think of make, mileage, number of doors, etc.  Classes can include other classes; like a car can contain an engine which in turn has attributes.  Also consider behaviors.

Attributes generally correspond to private member data; behaviors generally correspond to public functions.
Data encapsulation or data hiding, that is putting variables or functions into the private area, is important for shared programming.
Bad Example:

public: int [] getdata() {return somearray; } //Bad because arrays are returned by address.

Better Example

public: void getarray(int A[]) { for ( int i=0; i<10; i++) { A[i]=somearray[i];}}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: