Software Engineering I (02161)
Week 8
- Assoc. Prof. Hubert Baumeister
Software Engineering I (02161) Week 8 Assoc. Prof. Hubert - - PowerPoint PPT Presentation
Software Engineering I (02161) Week 8 Assoc. Prof. Hubert Baumeister DTU Compute Technical University of Denmark Spring 2018 Contents Basic Principles of Good Design Design Patterns Low Coupling High coupling A B C D E F Low
A B D E C F
A B D E C F
A B D E C F
Person name cpr-number companyName work-address-street work-address-city home-address-street home-address-city
Person name cpr-number companyName work-address-street work-address-city home-address-street home-address-city
Address street city Company name Person name cpr-number works at home address address
◮ the object itself ◮ its components ◮ objects created by that object ◮ parameters of methods
Order calculate price calculate base price calculate discounts Product name price Customer name discount info OrderLine quantity * 1 1
OrderLine quantity calculate price Customer name discount info calculate discount Product name price getPrice(quantity:int) Order calculate price calculate base price calculate discounts 1 1 *
Eric Evans, Domain Driven Design, Addison-Wesley, 2004
Hunt and David Thomas
Company name c-address-street c-address-city printAddress Address street city printAddress Company name Person name cpr-number works at home address address Person name cpr-number home-address-street home-address-city printAddress works at
◮ Use appropriate abstractions ◮ Inheritance ◮ Classes with instance variables ◮ Methods with parameters
◮ Takes time!! ◮ refactor for simplicity
◮ E.g. using the observer pattern because it might be
◮ tests, easy to refactor
◮ Use good OO principles ◮ High cohesion, low coupling ◮ Decentralized control ◮ SOLID principles (next week)
A Pattern Language, Christopher Alexander, 1977
◮ Pattern: a solution to a problem in a context ◮ Pattern language: set of related patterns
Kent Beck: ”Birds, Bees, and Browsers—Obvious sources of Objects” 1994 http://bit.ly/2q4h0GC
◮ the Wiki Wiki Web was invented for this purpose
◮ Abstract Factory, Builder, Factory Method, Prototype,
◮ Adapter, Bridge, Composite, Decorator, Facade, Flyweight,
◮ Chain of Responsibility, Command, Interpreter, Iterator,
◮ Frame (1000 kr) ◮ Wheel: 28 spokes (1 kr), rim (100 kr), tire (100 kr) ◮ Wheel: 28 spokes (1 kr), rim (100 kr), tire (100 kr)
Part cost computeCost() Assembly computeCost() * *
... ... spoke29:Part {cost = 1} tire1:Part {cost = 100} spoke28:Part {cost = 1} rim1:Part {cost = 100} spoke1:Part {cost = 1} frame:Part {cost = 1000} wheel2:Assembly whee11:Assembly bike:Assembly
Part cost computeCost() Assembly computeCost() {return cost} {int costs = 0; foreach (Assembly a : assemblies) { costs += p.computeCost(); } foreach (Part p : parts) { costs += p.computeCost(); } return costs; } * *
Book .. .. getMaxDaysForLoan():int Medium borrowDate .. .. getMaxDaysForLoan():int isOverdue(Calendar date):bool Cd .. .. getMaxDaysForLoan():int
ConcreteClass2 primitiveMethod1 primitiveMethod2 ... AbstractClass templateMethod primitiveMethod1 primitiveMethod2 ... ConcreteClass1 primitiveMethod1 primitiveMethod2 ... The template method defines its algortihm based on primitiveMethod1, ... PrimitiveMethod1, ... in AbstractClass are usually abstract, but they could also define some default behavior.
Design Patterns, Addison-Wesley, 1994
Design Patterns, Addison-Wesley, 1994
Eric Evans, Domain Driven Design, Addison-Wesley, 2004
Design Patterns, Addison-Wesley, 1994
Design Patterns, Addison-Wesley, 1994
◮ Shapes have a bounding box ◮ But text views only have an method GetExtent()
Design Patterns, Addison-Wesley, 1994
Design Patterns, Addison-Wesley, 1994
◮ Stuck with developing the analysis model. ◮ The model never is good enough. ◮ Each time one revisits the same problem, a new variant
◮ Solution: Proceed to design and implementation. This gives
◮ Observer Pattern ◮ Model-View-Controller (MVC)