Sie sind auf Seite 1von 4

905-FBAS/ BSSE /F-09 (B)

FACTORY DESIGN PATTERN

a)Factory pattern comes into creational design pattern category, the main objective of the creational pattern is to instantiate an object and in Factory Pattern an interface is responsible for creating the object but the sub classes decides which class to instantiate. It is like the interface instantiate the appropriate sub-class depending upon the data passed. Now in the example that we are looking at for explaining the Factory Design Pattern is we are creating an object of Dog and Cat without calling the Dog or Cat class. We have created an abstract class Mammals. This class will be used by the Dog and Cat class. We have created Cat class, this class extends from Mammals class. We have created Dog class, this class extends from Mammals class. We have to create an object for Dog class and for that we are not directly loading the Dog class. Instead we are instantiated the object for Mammals Factory class.

Class Diagram:

905-FBAS/ BSSE /F-09 (B)

Participants:
Mamals Cats Dogs Factory Client Mamals Factory

SINGLETON
a) Logging messages is one of the most common tasks performed in software applications. Logging appropriate messages at appropriate stages can be extremely useful for debugging and monitoring applications. We define a interface Logger that declares the interface to be used by the client objects to log messages. In general, an incoming message could be logged to different output media, in different formats. Suppose two implementer classes of the Logger are FileLogger and ConsoleLogger . FileLogger stores incoming messages to a log file. ConsoleLogger displays messages on the screen.

Suppose One of the implementers of the Logger interface , the FileLogger class, logs incoming messages to the file log.txt. Singleton is helpful when there is one physical instance of object what the object represents. This is true in the case of a fileLogger because there is only one physical Log file. In an application, when different objects try to log messages to the file, there could be a multiple instances of the fileLogger class in use by each of the client object.

Class Diagram:

905-FBAS/ BSSE /F-09 (B)

Participants:
FileLogger Logger Interface

PROXY
a)-A proxy object creates a single object. Clients request are first received by the proxy object but never processed directly by the Proxy object. Client request are always forwarded to the target object. Response to the request is guaranteed provide he communication between client and server location is working.

Class Diagram:

905-FBAS/ BSSE /F-09 (B)

Participants:
Customer Proxy Customer Interface Account Manager

Das könnte Ihnen auch gefallen