13-09-2012, 11:55 AM
Advanced Software Engineering
Software Engineering.docx (Size: 320.76 KB / Downloads: 36)
Design Patterns
A software design pattern describes a family of solutions to a software design problem. It consists of one or several software design elements such as modules, interfaces, classes, objects, methods, functions, processes, threads, etc., relationships among the elements, and a behavioral description.
The purpose of design patterns is to capture software design know-how and make it reusable. Design patterns can improve the structure of software, simplify maintenance, and help avoid architectural drift. Design patterns also improve communication among software developers and empower less experienced personnel to produce high-quality designs.
A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples. The solution is a general arrangement of objects and classes that solve the problem. The solution is customized and implemented to solve the problem in a particular context.
The Observer Pattern
Observer pattern used to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Key forces of this pattern:
i. There may be many observers
ii. Each observer may react differently to the same notification
iii. The subject should be as decoupled as possible from the observers to allow observers to change independently of the subject
Advantages
* Minimal coupling between the Subject and the Observer
* Can reuse subjects without reusing their observers and vice versa
* Observers can be added without modifying the subject
* All subject knows is its list of observers
* Subject does not need to know the concrete class of an observer, just that each observer implements the update interface
* Subject and observer can belong to different abstraction layers
* Support for event broadcasting
* Subject sends notification to all subscribed observers
* Observers can be added/removed at any time.
Disadvantages
* Possible cascading of notifications
• Observers are not necessarily aware of each other and must be careful about triggering updates
* Simple update interface requires observers to deduce changed item.