Professional Documents
Culture Documents
SOLID & Design Pattern UIT
SOLID & Design Pattern UIT
SOLID & Design Pattern UIT
• Objects in a program
should be replaceable with
instances of their subtypes
without altering the
correctness of that
program
I: Interface
segregation
principle
• Many client-specific
interfaces are better than
one general-purpose
interface
D: Dependency
inversion principle
• One should depend upon
abstractions, [not] concretions
1.High-level modules should not depend
on low-level modules. Instead, both
should depend on abstractions
(interfaces)
2.Abstractions should not depend on
details. Details (like concrete
implementations) should depend on
abstractions.
What is Design Pattern
• A reusable solution to common software design
problems
• Why?
• More flexible,
• Reusable
• Maintainable
Categories
• Creational
• Structural
• Behavioral
Creational Design Pattern
1.Factory Method
2.Abstract Factory
3.Builder
4.Prototype
5.Singleton
Structural Design Patterns
1.Adapter
2.Bridge
3.Composite
4.Decorator
5.Façade
6.Flyweight
7.Proxy
Behavioral Design Patterns
1.Chain of Responsibility
2.Command
3.Interpreter
4.Iterator
5.Mediator
6.Memento
7.Observer
8.State
9.Strategy
10.Visitor
11.Template Method
Singleton
design pattern
• A class has only one
instance, while providing
a global access point to
this instance
• Ensure that a class has
just a single instance.
• Provide a global access
point to that instance
Public sealed class Database{
private static Database instance
private Database() {}
public static method getInstance()
if (instance == null)
instance = new Database()
return instance
Example of
// For instance, all database queries of an app go
// through this method. Therefore, you can place
// throttling or caching logic here.
singleton // ...
class Application is
void main() is
Database foo = Database.getInstance()
foo.query("SELECT ...")
// ...
Database bar = Database.getInstance()
bar.query("SELECT ...")
// The variable `bar` will contain the same object as
// the variable `foo`.