diff --git a/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.png b/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.png new file mode 100644 index 0000000..45245cf Binary files /dev/null and b/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.png differ diff --git a/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.puml b/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.puml new file mode 100644 index 0000000..fae0ee4 --- /dev/null +++ b/topics/sw_concepts/images/abstract-factory/abstract-factory-bad-case.puml @@ -0,0 +1,66 @@ +@startuml + +class Bootstrap + +package views { + + class Header + + class MainView + +} + +package components { + + together { + interface Label + + class LightLabel + + class DarkLabel + } + + together { + interface Button + + class LightButton + + class DarkButton + } + + Label <|.. LightLabel + Label <|.. DarkLabel + + Button <|.. LightButton + Button <|.. DarkButton +} + +package legend <> { + <> example_diamond + + note left of example_diamond + if darkmode + endnote +} + +<> header_label + +<> main_label +<> main_button + +Bootstrap "creates" ---> Header +Bootstrap "creates" ---> MainView + +Header --> header_label +header_label --> LightLabel +header_label --> DarkLabel + +MainView --> main_label +main_label --> LightLabel +main_label --> DarkLabel + +MainView --> main_button +main_button --> LightButton +main_button --> DarkButton + +@enduml diff --git a/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.png b/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.png new file mode 100644 index 0000000..75eb0ef Binary files /dev/null and b/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.png differ diff --git a/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.puml b/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.puml new file mode 100644 index 0000000..637a5d9 --- /dev/null +++ b/topics/sw_concepts/images/abstract-factory/abstract-factory-good-case.puml @@ -0,0 +1,71 @@ +@startuml + +class Bootstrap + +package views { + + class Header + + class MainView + +} + +package components { + + together { + interface Label + + class LightLabel + + class DarkLabel + } + + together { + interface Button + + class LightButton + + class DarkButton + } + + interface ComponentFactory + + class LightComponentFactory implements ComponentFactory + + class DarkComponentFactory implements ComponentFactory + + + Label <|.. LightLabel + Label <|.. DarkLabel + + Button <|.. LightButton + Button <|.. DarkButton + + DarkComponentFactory --> DarkLabel + DarkComponentFactory --> DarkButton + + LightComponentFactory --> LightLabel + LightComponentFactory --> LightButton +} + +package legend <> { + <> example_diamond + + note left of example_diamond + if darkmode + endnote +} + +<> create + +Bootstrap "creates" ---> create +create --> LightComponentFactory +create --> DarkComponentFactory +Bootstrap "creates" ---> Header +Bootstrap ---> MainView + +Header --> ComponentFactory + +MainView --> ComponentFactory + +@enduml diff --git a/topics/sw_concepts/sw_concept_slides.md b/topics/sw_concepts/sw_concept_slides.md index 72974c8..d7f5f10 100644 --- a/topics/sw_concepts/sw_concept_slides.md +++ b/topics/sw_concepts/sw_concept_slides.md @@ -351,28 +351,33 @@ class CasiceConfigurationFactory: AbstractFactory ------- - +* Use Case: + * Es gibt 2 oder mehr Gruppen von Komponenten. Es sollen immer nur Komponenten aus einer der Gruppen erstellt werden. + * Beispiel Light/Dark Theme: es soll entweder Light oder Dark Theme sein, aber nie gemischt. + * Die gleichen If-Statements tauchen wiederholt an unterschiedlichen Stellen im Code auf. Man möchte diese Code-Duplizierung + verhindern, indem man die If-Statements an einem zentralen Ort platziert. -AbstractFactory Beispiel 1 +von [Java Design Patterns/AbstractFactory](https://github.com/iluwatar/java-design-patterns/tree/07663ce2bdd46ca4697307068b9eb0d4c8888ead/abstract-factory/README.md) + +AbstractFactory Beispiel: vorher ------ +\colBegin{0.8} +![AbstractFactory Beispiel: vorher](images/abstract-factory/abstract-factory-bad-case.png){width=100%} +\colNext{0.2} +\colEnd -```python -class ButtonFactory: - def get_bwd_button(self, name, dim, text): - return BwdButton(name, dim, text) +AbstractFactory Beispiel: nachher +------ - def get_fwd_button(self, name, dim, text): - return FwdButton(name, dim, text) +\colBegin{0.8} +![AbstractFactory Beispiel: nachher](images/abstract-factory/abstract-factory-good-case.png){width=100%} +\colNext{0.2} +\small - def get_info_button(self, name, info_text): - return InfoButton(name, info_text) +* Die Anzahl "if darkmode" statements ist reduziert. +* Es ist jetzt viel einfacher, ein "HighContrast"-Theme einzubauen. -class ButtonFactoryC(ButtonFactory): - pass - -class ButtonFactoryL(ButtonFactory): - pass -``` +\colEnd AbstractFactory Beispiel 2 ------