I.
UML
1. Association, Composition, Aggregation
In simple terms :
Both Composition and Aggregation are Associations. Composition -> Strong
Has-A relationship Aggregation -> Weak Has-A relationship.
https://www.geeksforgeeks.org/association-composition-aggregation-java/
Link https://www.javatpoint.com/association-in-java
UML arrow define, reference link
1.1. Association
Association in Java defines the connection between two classes that are set up
through their objects. Association manages one-to-one, one-to-many, and many-
to-many relationships. In Java, the multiplicity between objects is defined by the
Association.
+ UML
1.2. Aggregation
Aggregation is also a “has-a” relationship. What distinguishes it from
composition, that it doesn't involve owning. As a result, the lifecycles of the
objects aren't tied: every one of them can exist independently of each other.
+ UML
1.3. Composition
Composition is a “belongs-to” type of relationship. It means that one of the
objects is a logically larger structure, which contains the other object. In other
words, it's a part of or member of the other object.
Alternatively, we often call it a “has-a” relationship (as opposed to an “is-a”
relationship, which is inheritance).
For example, a room belongs to a building, or in other words a building has a
room. So basically, whether we call it “belongs-to” or “has-a” is only a matter of
point of view.
+ UML
II. Software Design
2. Some concept
2.1. Cohesion
- Cohesion is the degree to which the elements inside a module belong together.
- A module is said to have low cohesion if it contains unrelated elements. ->
increase complex
- ‘a module’ may be a class, a package, a module… -> in general, call it as
“elements”
- High Cohesion is BETTER
2.2. Coupling
- Coupling is the degree of interdependence between software modules.
- High coupling means object, class, module is more dependent. So change one
may affect to others.
- Low coupling is BETTER
3. Software architecture
3.1. MVC
Picture 2.1.2 MVC architecture
- Note: may MVC between others are different, but I follow by architecture: View
model is get data from Model -> View depend on Model (Some other resources,
people say that View get data via Controller, but it look like MVP – as my
wonder?). And it web & Android may be different, in Android View get User event
then request Controller to update data to Model
- Reference link: MVC, AspNetLink
- Model – data layer, is responsible for managing the business logic and handling
network or database API .
- Controller - the logic layer, gets notified of the user’s behavior and updates the
Model as needed.
- View – UI layer, a visualisation of the data from the Model.
- May relationship between Controller vs View is 1:N
- Both View & Controller depend on Model: the Controller to update the data to
Model, the View to get the data & display it.
- There are 2 kind of MVC.
+ Passive model: View get notify about data change from Controller:
+ Active model: View get notify directly about data change from Model:
3.2. MVP
Picture 2.2.1: MVP architecture
3.3. MVVM
3.4. MVC vs MVP vs MVVM’
4. Clean architecture
5. SOLID
6. Design pattern
6.1. Creational patterns
6.1.1. Singleton
6.2. Structural patterns
6.2.1. Adapter pattern
Also known as: Wrapper
https://refactoring.guru/design-patterns/adapter
The Adapter acts as a wrapper between two objects. It catches calls for
one object and transforms them to format and interface recognizable by
the second object.
https://www.vogella.com/tutorials/DesignPatternAdapter/article.html
The adapter pattern describes how to convert an object into another object
which a clients expects. This pattern mainly adapts one object to another one.
Adapters allow objects to work together that couldn’t otherwise because of
incompatible interfaces.
Adapter allows to reuse existing coding without changing it, as the adapter
ensures the conversion between the different interfaces.
https://springframework.guru/gang-of-four-design-patterns/adapter-pattern/
“Convert the interface of a class into another interface clients expect. Adapter
lets classes work together that couldn’t otherwise because of incompatible
interfaces.”
My conclusion:
Adapter connect two objects aren’t incompatible so them can able to
work together.
Example: we already have class B that implement ‘dientich’ calculate (note:
it’s same with reserve case, library provide B, but we need something like
interface A)
Class B {
Int square(Int a, Int b) {
Return a * a;
}
}
// but someone: library, others developer… requested we provide an object by
interface
Interface A {
Int dientich(int w, int h)
}
// so we create an adapter to satisfy of others request
class Adapter implements A{
private B b;
public Adapter(B b) {
this.b = b;
}
int dientich(int w, int h) {
return b.square(w, h);
}
}
}
6.2.2. Bridge
“Decouple an abstraction from its implementation so that the two can vary
independently.” reference
The bridge pattern does it by separating the abstraction and the implementation in
separate class hierarchies. The bridge between the class hierarchies is achieved
through composition.
Also, as stated by GOF “Adapter makes things work after they’re designed; Bridge
makes them work before they are.“
6.3. Behavioral patterns
6.3.1. Strategy
- “Define a family of algorithms, encapsulate each one, and make them
interchangeable. Strategy lets the algorithm vary independently from clients that
use it.” reference
- In computer programming, the strategy pattern (also known as the policy pattern)
is a behavioral software design pattern that enables selecting an algorithm at
runtime. Instead of implementing a single algorithm directly, code receives
run-time instructions as to which in a family of algorithms to use. wiki
- My define: when we have many/a family of algorithms, we should create a class
for each algorithm, then select one to execute for client at runtime instead of
bring all to one class – client?
- Example: Collections.sort(new Compartor())
6.3.2. Iterator
- “Provide a way to access the elements of an aggregate object sequentially
without exposing its underlying representation.” reference
- My state: provide a way to access elements of object sequentially without
exposing its structure & implement, example: traverse by depth first search or
breadth first search, we don’t care how it implement or structure, just provide
iterator interface -> call next(), hasNext()…
III. OOP
7. What is OOP?
““A way to model the real world” – chapter 5 – clean architecture