VIEWS: 1 PAGES: 12 POSTED ON: 10/10/2012
OO (Object Oriented) Programming Chapter 21 IB103 Week 12 A method of Design, (make the major decisions first when designing programs) OO object oriented programs “Balloon” as an example, a simulation of a balloon Principles of OOP 1. Encapsulation (Chapter 9) 2. Inheritance (Chapter 11) 3. Polymorphism Encapsulation …group related information together and protected from the outside (world) Private = protected or Open = open to the world Inheritance Use classes repeatedly Reuse parts of existing classes when possible Polymorphism Same methods used with others, multiple implementations Design problems Need to identify objects. An approach to problem solving Simulation and Modeling Build a software model of something in the real world Identify the object(s) in the problem Model them as objects Ignore irrelevant detail Specification = what is required Design = how it will be accomplished Model – view - controller An example: A cars engine (model) the observer = you gas pedal (controller) speedometer (some dial or gage) i.e. GUI What user adjusts with (a scrollbar (controller) as an example) A Balloon example Model - car engine vs. Balloon View – speedometer vs. Circle Controller – steering wheel vs. change position of Balloon (left/right, up/down) Hierarchy An old example “Sphere” class as the parent and Orb, or Circle, or marble or whatever as child. Many other sub classes possible Analyze the specifications of what you are to model (design) Write in pseudocode before using Java Case study in design “One Armed Bandit” example “Slotmachine”: “Actions” Display Go Query Stop Reuse the components that your program can inherit Relationships “is a” vs. “has a” Is a = inheritance (java “extends”) from parent class Has a = (java “new”) an object Needs a = utility (java various methods) need of another object, may pass in a parameter) Reuse components that your program can inherit Save time, money Tested before Build library Specific to organisation
"OO _Object Oriented_ Programming"