Department of Computer Engineering
Object-Oriented Design
Lecture 12: Object-Oriented Principles
Sharif University of Technology 1
Object-Oriented Design Lecture 12: Object-Oriented Principles - - PowerPoint PPT Presentation
Object-Oriented Design Lecture 12: Object-Oriented Principles Sharif University of Technology 1 Department of Computer Engineering Open Closed Principle (OCP) Classes should be open for extension but closed for modification. OCP states
Department of Computer Engineering
Sharif University of Technology 1
relationships between a concrete class and an abstract class or an interface.
Sharif University of Technology 2
Sharif University of Technology 3
Sharif University of Technology 4
Sharif University of Technology 5
Sharif University of Technology 6
Sharif University of Technology 7
don't change it.
Sharif University of Technology 8
Sharif University of Technology 9
Sharif University of Technology 10
Sharif University of Technology 11
inheritance is a reuse mechanism at the class level.
bonus:
class Employee { Money computeBonus() { /* skimpy default bonus */ } // etc.}
employees (managers) get more generous bonuses than others (secretaries and programmers):
class Manager extends Employee { Money computeBonus() { /* gerenous bonus */ } // etc.}
Sharif University of Technology 12
computation among programmers?
class SeniorProgrammer extends Programmer { Money computeBonus() { /* gerenous bonus */ } // etc.}
Would this require us to recompile any code?
managers get? What changes would we need to make?
class with the skimpy bonus algorithm?
Sharif University of Technology 13
class they instantiate.
dynamically.
Sharif University of Technology 14
Sharif University of Technology 15
Sharif University of Technology 16
Sharif University of Technology 17
Sharif University of Technology 18
Sharif University of Technology 19
i.e. the class that has the information necessary to fulfill the
Sharif University of Technology 20
Sharif University of Technology 21
Sharif University of Technology 22
Who should be responsible for knowing the grand total of a
an Expert with respect to creating A).
Sharif University of Technology 23
Sharif University of Technology 24
classes on which it is dependent.
Sharif University of Technology 25
Sharif University of Technology 26
Sharif University of Technology 27
Sharif University of Technology 28
Sharif University of Technology 29
class representing one of the following choices:
case- or session-controller).
scenario.
this list.
typically delegate these events to a controller.
Sharif University of Technology 30
and then controls/coordinates with other object of the domain layer to fulfill the request.
Sharif University of Technology 31
Sharif University of Technology 32
Sharif University of Technology 33
Sharif University of Technology 34
Sharif University of Technology 35
Sharif University of Technology 36
Sharif University of Technology 37
Sharif University of Technology 38
Sharif University of Technology 39
and/or data members – if the method is to behave correctly – PRIOR to running the code in the method.
a method (except constructors and destructors).
Sharif University of Technology 40
Sharif University of Technology 41
rejected by the ancestor.
Sharif University of Technology 42
Sharif University of Technology 43