CSCI 130 Classes and Objects
Classes Templates from which programmatic building blocks are constructed Model physical entities Have the ability to ‘construct’ instances of the templates Class contains: Attributes Behaviors
Example Write up the attributes and behaviors of a Car class
Objects Actual instance of a class In an object-oriented program objects interact with each other Objects may be constructed from other objects Black box concept Other objects don’t care how an object performs its tasks, only that it does perform them
Important OOP concepts The instances of each class have complete control over the accessibility of their attributes and behaviors as defined by the class Classes can be related in a hierarchical fashion from general to specific Some instances of classes have the ability to morph themselves into other (related) classes
Example Create a class hierarchy for all vehicle objects
Identifying Classes Done in design phase Most difficult part of OOP define, design, code, test, document Most difficult part of OOP must view entire system in OO terms good initial design leads to highly effective programming bad initial design leads to wasted time and effort