3. Definitions of Design Patterns
• “Design patterns are recurring solutions to design problems you see
over & over” [smaltalk Companion]
• “Design patterns constitute a set of rules describing how to
accomplish certain tasks in the realm of software development “
[Pree,1994]
• “Design patterns focus more on reuse of recurring architectural
design themes, while frameworks focus on detailed design &
implementation”[Coplien & Schmid ,1995]
3
4. Definitions of Design Patterns
• “A pattern addresses a recurring design problem that arise in
specific design situations & presents a solution to it” [Buschmann et
al.,1996]
• “Patterns identify & specify abstractions that are above the level of
single classes and instances, or of components.”[Gammar et
al.,1993]
4
5. Model-View-Controller
• The Model-View-Controller (MVC) pattern is one of the earliest and
one of the most successful design patterns. It was developed by
Trygve Reenskaug in 1979.
Controller
Data Model
View
5
6. Model-View-Controller
• Data Model : Contains the computation part of the program
• View : Which presents the user interface
• Controller : Which interacts between the user & the view
6
7. Model-View-Controller
• Employee Object as a Model
• EmployeeView a Class which display Employee Information as a View
• EmployeeControl a Class which controls the data flow into model
object and updates the view whenever data changes - Controller.
7
8. Model-View-Controller Interaction
• It helps to separate the application’s concerns
EmployeeController
EmployeeModel
EmployeeView
Sees Uses
ManipulateUpdate
8
9. Data Model
• Data ,methods for accessing and modifying state
• A model stores data that is retrieved according to commands from
the controller and displayed in the view
9
13. Controller
• Translate user actions into operations on the model. Act as a
separator between Model & View.
• A controller can send commands to the
• Model to update the model's state (e.g., editing a document)
• Associated view to change the view's presentation of the model (e.g., by
scrolling through a document).
13
19. Singleton Pattern
• Define a class that has only one instance(class must ensure that only
single instance should be created)
• Provides a global point of access to it(single object can be used by all
other classes)
“Is a class of which there may be no more than one instance. It provides single global
point of access to that instance”
19
20. Singleton Pattern – When to Use
• When it’s important to have only one instance of a class
• Only a print spooler
• One window manager
• One point of access to database engine
• Among several serial ports only one instance of COM1
• Centralized management of internal or external resources and they
provide a global point of access to themselves
• Singleton pattern is mostly used in multi-threaded and database
applications.
20
21. Forms of Singleton Pattern
Singleton Pattern
Early Instantiation
(Load Time instance
creation)
Lazy Instantiation
(Create instance
when required)
21
24. Singleton Pattern – Class
• Static member
• Store the instance of the class
• Get memory only once as it is static
• Private constructor
• Prevent creating instances outside the class
• Static factory method (“Static factory method is simply a static method that returns an instance of a class.“)
• Provides the global point of access to the Singleton object
• Returns the instance to the caller.
24
25. Singleton Pattern – Early Instantiation
• Create the instance of the class at the time of class loading
25
26. Singleton Pattern – lazy Instantiation
• Create the instance of the class in synchronized method or
synchronized block
• Instance of the class is created when required
26
28. Conclusion
• MVC Pattern stands for Model-View-Controller Pattern. This pattern
is used to separate application's concerns.
• Singleton Pattern Is a class of which there may be no more than one
instance. It provides single global point of access to that instance
28