Module_9
Module_9
The program designer must structure the programming tasks into a set of interrelated
classes. Each class must be specified precisely, listing both its responsibilities and its
relationship to other classes in the system.
The exact choice of data structures, for example, hash tables or binary search trees for
a collection, is not of concern in the design phase but is deferred until
implementation.
Major goals of the design phase:
Identify the classes, the responsibilities of these classes, the relationships among
these classes, etc.
• Inheritance (“is-a”) A class inherits from another if it incorporates the behavior of the
other class. (Details are provided in earlier modules)
Loosely Coupled: Patterns are loosely tied together with few connections,
making it easier to separate the patterns. They should promote quicker,
simpler for future changes.
Tightly Coupled: Patterns are tightly tied together with many links and
dependencies. Minor changes to one of the patterns will be difficult without
affecting the other(s).
“Open to extension” means that you should design your classes so that
new functionality can be added as new requirements are generated.
“Closed for modification” means that once you developed a class you
should never modify it, except to correct bugs.
class AreaCalculator {
public double calculateShapeArea(Shape shape) {
return shape.calculateArea();
}
}
The Liskov Substitution Principle (LSP) states that any instance of a derived
class should be substitutable for an instance of its base class without
affecting the correctness of the program.
UML Diagrams
(Module- 9b)
Recap: Object Oriented Design Symbols
Synchronized/ guarded
class cell {
private int value;
public void swap(cell other){
synchronized(this){
synchronized(other){
Example:
int newValue = other.value; Normal Run
other.value = value;
value = newValue;} }
}...
}
Deadlock
Thank
you
Q&A