1-Week3-ObjectOorientedProgramming-design.pdf

SarveshKumar991442 6 views 25 slides May 31, 2024
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

Oops design


Slide Content

The philosophy of OO programming
Madhavan Mukund
https://www.cmi.ac.in/~madhavan
Programming Concepts using Java
Week 3

Algorithms + Data Structures = Programs
Title of Niklaus Wirth's introduction to Pascal
Traditionally, algorithms come rstStructured programming
Design a set of procedures for specic tasks
Combine them to build complex systems
Data representation comes later
Design data structures to suit procedural manipulations
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Algorithms + Data Structures = Programs
Title of Niklaus Wirth's introduction to Pascal
Traditionally, algorithms come rstStructured programming
Design a set of procedures for specic tasks
Combine them to build complex systems
Data representation comes later
Design data structures to suit procedural manipulations
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Algorithms + Data Structures = Programs
Title of Niklaus Wirth's introduction to Pascal
Traditionally, algorithms come rstStructured programming
Design a set of procedures for specic tasks
Combine them to build complex systems
Data representation comes later
Design data structures to suit procedural manipulations
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Algorithms + Data Structures = Programs
Title of Niklaus Wirth's introduction to Pascal
Traditionally, algorithms come rstStructured programming
Design a set of procedures for specic tasks
Combine them to build complex systems
Data representation comes later
Design data structures to suit procedural manipulations
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design
Reverse the focus
First identify the data we want to maintain and manipulateThen identify algorithms to operate on the dataClaim: works better for large systemsExample: simple web browser
2000 procedures manipulating global data
. . . vs 100 classes, each with about 20 methodsMuch easier to grasp the designDebugging: an object is in an incorrect stateSearch among 20 methods rather than 2000 procedures
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design: Example
An order processing system typically involves
Items
Orders
Shipping addresses
Payments
Accounts
What happens to these objects?
Items are
Orders are,
Payments are
Nouns
Associate with each order, a method to add an item
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design: Example
An order processing system typically involves
Items
Orders
Shipping addresses
Payments
Accounts
What happens to these objects?
Items are
Orders are,
Payments are
Nouns
Associate with each order, a method to add an item
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Object Oriented design: Example
An order processing system typically involves
Items
Orders
Shipping addresses
Payments
Accounts
What happens to these objects?
Items are
Orders are,
Payments are
Nouns
Associate with each order, a method to add an item
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Designing objects
Behaviour | what methods do we need to operate on objects?
State | how does the object react when methods are invoked?
State
Encapsulation | should not change unless a method operates on it
Identity | distinguish between dierent objects of the same class
State may be the same | two orders may contain the same item
These features interact
State will typically aect behaviour
Cannot add an item to an order that has been shipped
Cannot ship an empty order
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Designing objects
Behaviour | what methods do we need to operate on objects?
State | how does the object react when methods are invoked?
State
Encapsulation | should not change unless a method operates on it
Identity | distinguish between dierent objects of the same class
State may be the same | two orders may contain the same item
These features interact
State will typically aect behaviour
Cannot add an item to an order that has been shipped
Cannot ship an empty order
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Designing objects
Behaviour | what methods do we need to operate on objects?
State | how does the object react when methods are invoked?
State
Encapsulation | should not change unless a method operates on it
Identity | distinguish between dierent objects of the same class
State may be the same | two orders may contain the same item
These features interact
State will typically aect behaviour
Cannot add an item to an order that has been shipped
Cannot ship an empty order
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Designing objects
Behaviour | what methods do we need to operate on objects?
State | how does the object react when methods are invoked?
State
Encapsulation | should not change unless a method operates on it
Identity | distinguish between dierent objects of the same class
State may be the same | two orders may contain the same item
These features interact
State will typically aect behaviour
Cannot add an item to an order that has been shipped
Cannot ship an empty order
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Relationship between classes
Dependence
OrderneedsAccountto check credit status
Itemdoes not depend onAccount
Robust design minimizes dependencies, or
Aggregation
OrdercontainsItemobjects
Inheritance
One object is a specialized versions of another
ExpressOrderinherits fromOrder
Extra methods to compute shipping charges, priority handling
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Relationship between classes
Dependence
OrderneedsAccountto check credit status
Itemdoes not depend onAccount
Robust design minimizes dependencies, or
Aggregation
OrdercontainsItemobjects
Inheritance
One object is a specialized versions of another
ExpressOrderinherits fromOrder
Extra methods to compute shipping charges, priority handling
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Relationship between classes
Dependence
OrderneedsAccountto check credit status
Itemdoes not depend onAccount
Robust design minimizes dependencies, or
Aggregation
OrdercontainsItemobjects
Inheritance
One object is a specialized versions of another
ExpressOrderinherits fromOrder
Extra methods to compute shipping charges, priority handling
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java

Summary
An object-oriented approach can help organize code in large projects
This course is
Nevertheless, useful to know the motivation underlying OO programming to
understand design choices in a programming language like Java
Madhavan Mukund The philosophy of OO programming Programming Concepts using Java