COMP 105 Object Oriented Programming and Design Tutor
COMP 105 Object Oriented Programming and Design Tutor: Alex Green
Contact Information admin@greenai. com www. bcctutor. org
Course Information 4 quizzes (best 3 of 4) In class assignments Final Exam during last week (Do You Prefer Thursday or Friday? )
Object Oriented Programming Terminology
Topics to Be Considered Object orientation Object Classes Messages Encapsulation Abstraction Polymorphism Inheritance
What Is Object Orientation? Represent ‘objects’ that we find in the real world in software.
What Is an Object? An object is a thing Attributes ( characteristics) Behavior
E. G. Your “Bimma” ATTRIBUTES: BEHAVIOUR: • Make: BMW • Lights go on • Model: 2001 • Lights go off • Engine Number: • Accelerate #14565667 • Number of Cylinders: 9 • Colour: Silver • Etc. • Engine goes on • Engine goes off • Etc.
Classes A class is a category of similar objects. Objects are grouped into classes. A class defines the set of shared attributes and behaviors found in each object of the class. An object is an “instance” of a class.
E. G. Vehicle Class Make Model Engine# #of cylinders Color
E. G. Vehicle Class Objects
Messages Objects communicate with each other by sending messages.
An Example An object “Bad boy Driver” of the Driver class is sending a message to an object “Red bimma” of the vehicle class. That message is… Start Car
An Example As a result of the message the car starts. Start Car Note that the Driver and Vehicle classes would have been programmed to send and receive a Start Engine message.
C++ Vehicle Class class Vehicle { private: string model; string make; int number. Of. Cylinders; int engine. Number; string color; bool engine. On; float speed; bool lights. On; public: Vehicle(); void display(); int get. Num. Of. Cylinders(); void switch. Lights. On. Off(); void switch. Engine. On. Off(); void accelerate(int amt); }; Attributes Behaviors
Abstraction involves focusing on the relevant properties rather than the details.
Abstraction Different views of the same object. # of cylinders # of spark plugs Type of oil Size of engine
Abstraction Different views of the same object. Features Price Color
Encapsulation OOP encapsulates data (attributes) and functions (behaviour) into packages called objects; the data and functions of an object are intimately tied together.
Encapsulation (Information Hiding) Objects may know how to communicate with each other across well-defined interfaces but are normally not allowed to know how other objects are implemented— implementation details are hidden within the objects themselves.
Encapsulation (Information Hiding) Attributes Interface Object
Encapsulation (Information Hiding) Interface Message Attributes Object
Polymorphism The ability of different objects to respond to the same message but in class specific ways.
Polymorphism Speak Bow wow Meow. purrr. Tweet
Inheritance A relationship among classes whereby a class derives properties from a previously defined class.
Inheritance Vehicle Automobile Car Motorcycle Truck
- Slides: 26