plg Flashcards
tenta
Low coupling (Grasp principles)
Reduce impact of change by minimized coupling.
More Reuse.
Relies on few classes.
• Keep classes weakly connected/knowledgeable of others.
High Cohesion (Grasp)
Used to Manage and keep complexity low.
Reduce by :
- Keeping related responsibilities together in one class. (Used together? Keep together )
- Assign responsibilities so that cohesion remains high.
• Keep classes highly focused, manageable, understandable.
Information Expert (Grasp)
The class with the most knowledge about something should be responsible for it.
AKA : Assign responsibility to the information expert.
• Assign responsibility where most information exists to fulfill it.
Creator (Grasp)
Who should create object?
Whoever is closest to.
Alternativ:
A innehåller objekt av B
● A aggregerar (äger, kontrollerar) objekt av B
● A bokför objekt av B (A är t.ex. någon typ av rapport
● A ofta använder B
● A har det data som krävs för att initiera en instans av B.
Ex User interface transaction initiation -> Creates classes involed with transaction.
Like mvvm.
(Also As new classes are needed : whoever needs them, creates them.)
• Creates C if aggregates- , records-, closely uses- or has initializing info. for C.
Controller (Grasp)
Who’s in Controller?
- Assign the responsibility for receiving or handling a system event message to a class representing the overall system.
- Assign a use case scenario within which the system events occurs.
Controller gör inte allt. Utan endast att kontrollera och pass vidare uppgifter.
A problem that was originally out of the extension of 2 Tier applications.
• Represents overall system/use case scenario (controls a system operation).
PoluMorphism (Grasp, Many forms)
Put the responsibility for a method where it makes sense.
- Assign to its subtype
- Assign responsibility to handle related but varying elements based on elements type.
Ex Circle and Triangel is under Shapes (Arv)
• Assign responsibility for variation of behaviors based on type.
Pure fabrication (Grasp)
You may need to fabricat a class just to put method. (since its better than having it somewhere not related to the method)
Ex creating a class to have the code for observer pattern.
• Class specially made up to achieve low coupling and high cohesion.
Protected variation (Grasp)
Protect against variations/chang by wrapping classes in an interface
https://www.youtube.com/watch?v=pIJbp5Q3jhQ
Solid
Examine if your object are either well design or in good shape.
All of these patterns try to keep each objects coherent and tidy and not dependent on others. Aka increase cohesion and lower coupling.
Single Responsibility (Solid)
Every class should have responsibility over a single part of the functionality provide by the software.
One major responsibility.
And not try piling up things.
Narrow!
Open Closed principle (Solid)
A class should be open for extension but closed for modifications.
The idea:
IF you have a fully functional class that you want to change then:
Change the behaviour by extending and not modifying.
Aka change modules without changing source code.
(Because if you extend then all of the existing software will continue run without need for maintenance .)
Liskov Substitution (Solid)
Subclasses should be able to substitute for their base classes.
Alltså:
“Objekt i ett program bör ersättas med förekomster (instanser) av deras undertyper (subtyper) utan att ändra programmets korrekthet.”
Child object/Subclass should not change that what is central to the class.
(Typ hur om en subklass förvinner )
Interface Segregation (Solid)
No client should be force to depend on method it does not use.
This splits interfaces (which are large) into smaller and more specific ones.
Many specific interfaces are better than one general purpose interface.
Ha Alumni interface och anställd interface istället för att ha interface “person”.
Detta gör att man släpper köra kodrader och klasser i onödan (genom att skapar specifika interfaces).
Dependency Inversion (Solid)
Depend on abstraction. Not concretions.
A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.
Structural element
We are interested in the interaction between the structural element of a system ( the classes and relationship between). their externally observable properties and the relationships berween them, but its purpose is to support the system.