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