



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Week 8 & 9
Types of Pattern There are 3 types of pattern …
Forces: Can make an object globally accessible as a global variable, but this violates encapsulation. Could use class (static) operations and attributes, but polymorphic redefinition is not always possible. Solution: Create a class with a class operation getInstance(). When class is first accessed, this creates relevant object instance and returns object identity to client. On subsequent calls of getInstance(), no new instance is created, but identity of existing object is returned. Singleton Structure Singleton
**- uniqueInstance
Pattern: Façade (Structural) Name: Façade Problem: How can we access a large number of classes with a complex internal interaction in a simple but safe way? Solution: Introduce a dedicated interface class that simplifies the view of the class collection. Facade Structure Facade subsystem classes
<<façade>> SecurityManager +addAccessRight() +addActor() +addActorRole() +removeActor() AccessRight +addAccessRight() Actor +addActor() +removeActor() +changeSalary() ActorRole +addActorRole() Method not in Facade Pattern Name Comments
Colleague Concrete Colleague Concrete Colleague
Colleague Browser Text_Field My_Application Button
Pattern: Observer (Behavioral) Name: Observer Problem: Define a one-to-many dependency among objects so that when one object changes state, all of its dependents are notified and updated automatically. Solution : MVC, but refined by separating abstract from concrete subjects and observers Observer ConcreteObserver Update() observerState update() Subject ConcreteSubject attach(Observer) detach(Observer) notify() subjectState () getState() setState()
observerState = subject.getState( ) return subjectState for all o in observers { o.update( ) }
Factory Structure AbstractProduct ConcreteProduct AbstractFactory ConcreteFactory FactoryMethod() AnOperation() FactoryMethod() Product = FactoryMethod() return new ConcreteProduct()
MyClass createObjectOfRequiredClass():RequiredClass Factory design pattern Client RequiredClass Factory Class Model create objects Factory Example