3 Classes (2 implementation + interface) # of cylinders, # of wheels -> pass parameters
Object-Oriented Programming Tuesday, March 10, 2009 9:07 AM
3 Important Concepts in OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism What is an Object-Oriented Program? - Consist of a group of co-operating objects, exchanging messages to achieve a common objective. What is an Object? - A software construct that encapsulates data, along with the ability to use or modify that data into a software entity. What is Encapsulation? - Encapsulation is the concept of that an object should totally separate its interface from its implementation. All the data and implementation code for an object should be entirely hidden behind its interface.
-
State of an Object? An object has changed its state when one or more data values stored in the object have been modified. When an object responds to a message, it will usually perform an action, change its state return a value or some combination of the above.
Persistence? - The ability of your car radio to remember your list of favourite stations is often referred to as persistence. An object that has the ability to store and remember values is soften said to have persistence. Class Definition? - A set of plans for an object allows you to mass produce lots of copies of the object. Instance of a Class? - An instance of a class - particular example of a software object. Instantiate a Class? - Produce an instance of a class. Invoking a Method of an Object? Public void playStation (in stationNumber) //causes the specific station identified by the integer to be selected for play //void - doesn't return a value //public - available to outside modifiers. myObRef.playStation(3) invokes this method, asks for station 3.
ICS4M0-A Page 1
Class Radio03 - Interface - Instantiate Combo (composition) - Radio03 has a Combo Class Combo extends Radio03 - Combo is a Radio03 type object - Inherits methods from Radio03
Method Overriding: means you have two or more methods in a super class and or subclass which have the same name, with slightly refined functions; but the same parameters. The version of the polymorphic method called is the one closest to the call location. Polymorphism: Multiple methods with the same name. Method Overloading: 2 or more methods in a class or set of classes which have the same name, but different parameter lists.