0% found this document useful (0 votes)
19 views4 pages

Kotlin Factory Pattern Explained

The document discusses three design patterns: Factory pattern which creates objects without specifying their classes, Singleton pattern which ensures only one instance of a class is created, and Proxy pattern which acts as an interface to a real object to control access. Class diagrams and descriptions of participants are provided for each pattern to illustrate how they work.

Uploaded by

abdulbarimalik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Kotlin Factory Pattern Explained

The document discusses three design patterns: Factory pattern which creates objects without specifying their classes, Singleton pattern which ensures only one instance of a class is created, and Proxy pattern which acts as an interface to a real object to control access. Class diagrams and descriptions of participants are provided for each pattern to illustrate how they work.

Uploaded by

abdulbarimalik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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 [Link]. 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

You might also like