Download presentation
Presentation is loading. Please wait.
1
Object-Oriented Programming
In Pursuit of Absolute Simplicity
2
How Can We Learn A Language
How to Learn A Natural Language Grammar, Culture How to Learn A PL Syntax/Grammar Algorithm A programming paradigm is presented. Hard!!! Hard!!! A programming paradigm is a pattern of problem-solving thought that underlies a particular genre of programs and languages.
3
Programming Paradigms
Four Programming Paradigms: Imperative Object-oriented Functional Logic (declarative) What problem does OO paradigms solve? Software crisis: due to the rapid increases in computer power and the complexity of the problems that could be tackled.
4
How Does Industry Do? Let us take a look at the automotive industry
5
What is the Goal/Principle of OOP?
To address the problem in SW, OOP aims to develop a SW system like how automobile is made in the automotive industry. OOP has some of important principles: When new requirements for a component are considered, just replace it with a new one. Open for Extension and Close for Modification!
6
What Does OOP Provide Main concepts/features in OOP
Class Interface Inheritance/polymorphism Message passing The key idea is how to use these main concepts in OOP?
7
Metaphor: Travel Adapter
Computer Travel Adaptor: three pins to two pins adaptor
8
Travel Adaptor in Programming
We assume a computer has turn_on feature which calls get power via three pins class Computer { private Boolean on; … public void turn_on() { on = get_power_via_3pins(); if(on) System.out.println(“Power is on”);} public boolean get_power_via_3pins(){ System.out.println(“Power is generated”); return true; }
9
Is the First Version a Good Program?
No. Why? How to make it better? class Computer { private Boolean on; … public void turn_on() { on = get_power_via_3pins(); if(on) System.out.println(“Power is on);} } class Computer { private Boolean on; … public void turn_on() { on = p.get_power_via_3pins(); if(on) System.out.println(“Power is on);} } class PowerOutlet { } private PowerOutlet p; public Boolean get_power_via_3pins(){ System.our.println(“Power is generated”); return true; } public boolean get_power_via_3pins(){ System.our.println(“Power is generated”); return true; }
10
Why 2nd version is better?
In Reality class PowerOutlet { } public Boolean get_power_via_3pins(){ System.out.println(“Power is generated”); return true; } class Computer { private Boolean on; … public void turn_on() { on = p.get_power_via_3pins(); if(on) System.out.println(“Power is on);} } private PowerOutlet p;
11
Don’t forget to Buy Objects Separately?
Remember class is just a script and you need to buy these objects to get the real services for another complicated service class Application { } Why you cannot put the creation of object, i.e.main method in any of the previous two classes??? public static void main(…){ Computer c = new Computer(); PowerOutlet p = new PowerOutlet(); c.setPower(p); c.turn_on() }
12
What Happens When PowerOutlet Class Does not Work?
In Reality: In OO Code X class Computer { private Boolean on; … public void turn_on() { on = p.get_power_via_3pins(); if(on) System.out.println(“Power is on);} } class PowerOutlet { } public Boolean get_power_via_3leg(){ System.out.println(“Power is generated”); return true; } private PowerOutlet p; class PowerOutletVia2Pins{ public Boolean get_powerVia2pins() {System.out.println(“Power is generated via 2 legs”); return true; } class Adaptor extends PowerOutlet{ private PowerOutletVia2Pins p2; public Boolean get_power_via_3leg(){ return p2.get_powerVia2leg(); }
13
Don’t forget to Buy Adaptor!
For your Application Class: Class Application { } public static void main(…){ Computer c = new Computer(); PowerOutletVia2Pins p2 = new PowerOutletVia2Pins(); PowerOutlet p = new Adpator(); p.setPowerVia2Legs(p2); c.setPowerOutlet(p); c.turn_on() }
14
Importance of Interface
There are two interfaces <<interface>> IComputer turnOn() <<interface>> IPowerOutlet get_power_via_3Pins() Computer PowerOutlet Adapter In scenario 1, you create a Computer and Power object and connect them together. In scenario 2, the Power object is not available, but your computer object can be still used.
15
DCG vs Interfaces Divide, Conquer, and Glue (DCG) is closely related to interfaces. Ex. Check whether a string consisting of ‘(‘ and ‘)’ is balanced or not. (()()): valid and (() invalid <<interface>> CheckBalanceString <<interface>> Stack <<interface>> StringTobeHandled getValidString();//only ‘(‘ and ‘)’ setStringTobeChecked(…) CheckBalancedParenthesis(); Push(….); Pop(); Console WebInt ArrayImpl DBLinkedList
16
Commercial Off The Shelf software(COTS)
However, like all human-made artifacts, OO languages have advantage as well as disadvantage when developing a SW system!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.