WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here.here These slides contain a lot of animations. For optimal results, watch in slideshow mode.
bar() Main foo()
bar() Main foo()
Data, functions
How to structure?
……………….. 1. …………………2. ……………….. ……………………… …………..4. …………….. How to structure? ………………………. ……………. …………………………..
1234 How to structure?
???? ???? ???? MOV AL, 1h MOV CL, 2h MOV DL, 3h ???? MOV AL, 1h MOV CL, 2h MOV DL, 3h ??? int i i=5 ??? int i i=5
BINARY BINARY ASSEMBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEMBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5
BINARY BINARY ASSEMBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEMBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5 [Styles of structuring a solution]
BINARY BINARY ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5 PROCEDURAL function1 function array list PROCEDURAL function1 function array list
BINARY BINARY ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5 PROCEDURAL function1 function array list PROCEDURAL function1 function array list OBJECT- ORIENTED Other paradigms OBJECT- ORIENTED
1234 How to structure? Follow a paradigm Object Oriented Programming OOP
Designing component internals using Object-Oriented Programming
BINARY BINARY ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5 PROCEDURAL function1 function array list PROCEDURAL function1 function array list OBJECT- ORIENTED Other paradigms OBJECT- ORIENTED
BINARY BINARY ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h ASSEBLY MOV AL, 1h MOV CL, 2h MOV DL, 3h High-Level Languages int i i=5 High-Level Languages int i i=5 PROCEDURAL function1 function array list PROCEDURAL function1 function array list OBJECT- ORIENTED Other paradigms OBJECT- ORIENTED
Let’s follow real world
World = a network of objects collaborating by way of message + response OBJECT- ORIENTED Let’s follow real world
OBJECT- ORIENTED Object [ Data + related functions] Structure solution as collaborating objects. intuitive OBJECT- ORIENTED Let’s follow real world efficient?
OBJECT- ORIENTED Object [ Data + related functions] Structure solution as collaborating objects.
1234 How to structure? Follow a paradigm OOP Collaborating objects
1 23 4
1 23 4
OBJECT- ORIENTED Object [ Data + related functions] Structure solution as collaborating objects.
OBJECT- ORIENTED Object [ Data + related functions] Structure solution as collaborating objects.
OBJECT- ORIENTED Object [ Data + related functions]
OBJECT- ORIENTED Object [ Data + related functions]
More details Less details Object Data function Data X X
Object [ Data + related functions] An object closely-related behavior and data is an of Object Data function Data X X
Object [ Data + related functions] An object closely-related behavior and data is an of Object Data function Data X X
Object [ Data + related functions] An object closely-related behavior and data is an of Object Data function Data X X
Object Data function
1234 How to structure? Follow a paradigm OOP Collaborating objects 1. Abstraction2. ………………….3. …………..4. ……………..
data1 data2 data1 data2 function3 f2 function1 Object [ Data + related functions]
data1 data2 data1 data2 function3 f2 function1
data1 data2 data1 data2 function3 f2 function1
data1 data2 data1 data2 function3 f2 function1
data1 data2 data1 data2 function3 f2 function1 Interface/implementation separation
data1 data2 data1 data2 function3 f2 function1
An object closely -related behavior and data data1 data2 data1 data2 function3 f2 function1
1234 How to structure? Follow a paradigm OOP Collaborating objects 1. Abstraction3. …………..4. ……………..2. Encapsulation
data1 data2 data1 data2 function3 f2 function1
OO program at runtime… data1 data2 data1 data2 function3 f2 function1 data1 data2 data1 data2 function3 f2 function1 data1 data2 data1 data2 function3 f2 function1
data1 data2 data1 data2 function3 f2 function1 data1 data2 data1 data2 function3 f2 function1 data1 data2 data1 data2 function3 f2 function1 ProceduralOO function1 function array list function1 function array list
ProceduralOO Problem: Calculate the average age of students in a class. Assume DoB of each student is known.
Procedural Problem: Calculate the average age of students in a class. Assume DoB of each student is known. Functions Data
Procedural Functions Data Problem: Calculate the average age of students in a class. Assume DoB of each student is known.
OO
Data = DOB Behavior = getAge() Behavior = calculateAvgAge() Data = students
OO Data = DOB Behavior = getAge() Behavior = calculateAvgAge() Data = students
At runtime [ …]
Student -DOB -Name +getAge() +getName()
Student -DOB -Name +getAge() +getName()
Student -DOB -Name +getAge() +getName()
Student -DOB -Name +getAge() +getName()
Student -DOB -Name +getAge() +getName() A blueprint for creating objects.
Admin -students +calculateAvgAge() Student -DOB -Name +getAge() +getName()
1234 How to structure? Follow a paradigm OOP Collaborating objects 1. Abstraction3. …………..4. ……………..2. Encapsulation Blueprints for objects
ProceduralOO Functions Data Student -DOB -Name +getAge() +getName() Admin -students +calculateAvgAge()
ProceduralOO Functions Data Student -DOB -Name +getAge() +getName() Admin -students +calculateAvgAge()
UILogicStorage
UI Logic Storage Example: CityConnect Logic API: addRoute(String city1, String city2, int distance): String getDistance(String city1, String city2): String
Example: CityConnect Logic API: addRoute(String city1, String city2, int distance): String getDistance(String city1, String city2): String ? ? ? ? ? ? ? ? ? ?
Object behavior Object structureClass structure API: addRoute(String city1, String city2, int distance): String getDistance(String city1, String city2): String ? ? ? ? ? ? ? ? ? ?
Object behavior Object structureClass structure
Object behavior Object structureClass structure Logic UI Logic UI
Object behavior Object structureClass structure Logic UI Logic UI
Object behavior Object structureClass structure
Object behavior Object structureClass structure
Object behavior Object structureClass structure
Object behavior Object structureClass structure Object diagramClass diagram
Object behavior Object structureClass structure Object diagramClass diagram
Object behavior
object creation
Object behavior Object diagramClass diagram
CCLogic -routes:Route[] +addRoute(…) +getDistance(…) Route Class diagram
CCLogic -routes:Route[] +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route Class diagram
CCLogic +addRoute(…) +getDistance(…) Route
Object diagram
Object behavior
Object diagram
Class diagram CCLogic +addRoute(…) +getDistance(…) Route City -name
Class diagram CCLogic +addRoute(…) +getDistance(…) Route City -name
Class diagram CCLogic +addRoute(…) +getDistance(…) Route City -name
Class diagram
Sequence diagrams Object diagram(s)Class diagram
Sequence diagrams Object diagram(s)Class diagram
1234 How to structure? Follow a paradigm OOP Collaborating objects 1. Abstraction3. …………..4. ……………..2. Encapsulation Blueprints for objects Object rules Object structure Object behavior Apply OOP in CE2, Project
CCLogic +addRoute(…) +getDistance(…) Route City -name What is the multiplicity here? (a) 1 (b) 0..1 (c) 1..* (d) * start {a|b|c|d} e.g. start c OR tinyurl.com/answerpost feed2103 blah…