Professional Documents
Culture Documents
Java Test
Java Test
Object-Oriented Design
Principles
• Encapsulation
• Hierarchy
– Association, Aggregation
– Inheritance
• Polymorphism
Execution
Engine 3. Took weeks to get
(chokes on Frontend this issue resolved
certain names of
objects)
Venkat Subramaniam 2. Fixes the restriction TEST-9
DRY
• Some times hard to realize this
• It is much easier to copy, paste and
modify code to get it working the way
you want it, isn’t it
Related topics:
MVC
Alarm
Control
Analysis model stereotypes : System
+alert()
Gui Framework
Forced to accept V 1.2
Irrelevant change
User
Of Module
Tight coupling
Poor Cohesion
Bad for resuse
Bertrand Meyer:
“Software Entities (Classes,
Modules, Functions, etc.) should
be open for extension, but closed
for modification”
Piston
Car
Engine
public/is-a
B
B publicly inherits from (“is-a”) A means:
• every object of type B is also object of type A
• whats true of object of A is also of object of B
• A represents a more general concept than B
• B represents more specialized concept than A
• anywhere an object of A can be used, an object of
B can be used
Venkat Subramaniam TEST-25
Behavior
Design by Contract
Advertised Behavior of the
Derived class is Substitutable for that of
the Base class
Substitutability: Derived class Services
Require no more and promise no less
than the specifications of the
corresponding services in the base class
Clock Timer
• Dependency has been inverted
• Both Controller and Clock depend on
Abstraction (IAlarm)
• Changes to Clock does not affect
Controller
• Better reuse results as well
Venkat Subramaniam TEST-32
DIP
• Dependency Inversion Principle
C1 C2
A Class
IMicrowave
C1 C2
+cook(time)
Clients are forced to +stop()
use interfaces they +chime()
do not care about. +notify(…)
May result in greater
coupling, dependency All implementations must
to more libraries carry the weights
MicrowaveImpl
Venkat Subramaniam TEST-36
ISP
• Interface Segregation Principle
• “Clients should not be forced to depend
on methods that they do not use”
IMicrowave
C1 C2
+cook(time)
+stop()
INotify IChimer
+notify(…) +chime()
MicrowaveImpl1 MicrowaveImpl2
• Release
– A class generally collaborates with other
classes
– For a class to be reused, you need also
the classes that this class depends on
– All related classes must be released
together
A
(0, 1) Th Highly
eM (1,1) instable &
Abstractness
Maximally a in abstract
Se
stable qu (Rigid)
en
& abstract ce
(1, 0)
0
Highly Instability I
Maximally
stable &
instable
Concrete
Venkat Subramaniam(Rigid)
& concrete TEST-53
Distance from the
main sequence
• D = |(A + I - 1) / 2 |