{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 9 - Classes - Class Implementation • Is the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Class What is a Class? Is a set of objects that share a common structure and common behaviour o Have common attributes (instance variables) But usually different values for these attributes o Have common methods (instance methods) A class is an abstraction, a way of classifying similar objects Sometimes we treat the class as an object o We send messages to it i.e. invoke a class (static) method o We store data in it i.e. use class (static) variables Class Interface Is the outside view of a class Consists of declarations of methods and variables The accessibility of these methods and variables can be set: o public: accessible to all clients o protected: accessible to the class itself, and all subclasses o private: accessible to only the class itself Instance variables are usually declared private o Allows us to encapsulate the state of an object Instance methods are usually declared public
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Class Implementation • Is the inside view of a class • Consists of method (member function) definitions o I.e. code that implements behaviour • In C++ o The implementation is put into a .cc or .cpp file o The interface is put into a .h file • In Java, the interface and implementation are not separated (uses only a single file) Representing a Class in UML (Unified Modeling Language) • General form for the class symbol: Refer to Lecture 9 UML .jpg • Attributes follow the form: name : type • E.g. lastName : String length : int • Operations follow the form: name(arguments) : returnType • Each argument follows the form: name : type • Arguments are separated by commas • E.g. getAge() : int setLength(value : float) : void • Visibility can be specified, if desired: o public + o protected # o private-...
View Full Document

{[ snackBarMessage ]}