You are on page 1of 9

Dessign Patterns

● Creational
● Structural
● Behavioural

IntelliJ (Java)

public: accesible anywhere in these code base | private: access modifiers


static: we can call this method directly without having to create an instance of the main class
void: This method is not going to return a value

Coupling
How a class can be affected by another class
In this example the main class in couple/depended on the user class

Avoid cascading changes


Interfaces
- A contract that specifies the capabilities a class should provide

- Allows us to build loosely coupled applications

Encapsulation
Setter/Getter

Bundling the data and methods than operate on the data within one unit or class and hiding
the values or state of an object inside the class
*It’s not necessary to write this. besides the getter method of balance because as it not have
any parameters would not confuse balance with them

Abstraction
Reduce complexing by hiding unnecessary details in our classes
Make methods private -> SendEmail() called connect(),sendEmail(), and disconnect()

Inheritence -> extends


A mechanism for reusing code

Polymorphism
The ability of an object to take many forms

public abstract void draw(); method decoration.


UML - Unified Modeling Language
Visual language that we use to model our systems

- (-) Minus sign defines that the method was declared private
- (+) Plus sign defines that the method was declared public
- If we don’t add ; (semicolon) to the method it’s because it doesn’t return any value
Relationships between classes

Inheritance relationship / Extend


“The Rectangle class extends from the Shape class”
Composition relationship

“The Shape class is composed by the Size class”

Dependency Relationship

“Somewhere in the shape class we have a reference to the Document Class”


Design Patterns

Memento Pattern

We use this pattern for implementing undo mechanisms

Declare variable as final means once initialized we cannot accidentally change it on our
program

State Pattern

Allows an object to behave differently when its state changes


Related with polymorphism
Lack of extensibility
If in the future we have to add a new tool, we only have to create the respective class that
implements Tool methods -> Open closed principle!

Abusing the design pattern


You have to learn when and how to apply them

Simplicity is the ultimate sophistication

You might also like