Skip to content

Commit

Permalink
sw_concepts: replace abstract-factory example
Browse files Browse the repository at this point in the history
Use self drawn stripped down version of the diagram.
  • Loading branch information
BacLuc committed Apr 19, 2024
1 parent f729792 commit 283a994
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 16 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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 <<Rectangle>> {
<> 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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 <<Rectangle>> {
<> 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
37 changes: 21 additions & 16 deletions topics/sw_concepts/sw_concept_slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,33 @@ class CasiceConfigurationFactory:
AbstractFactory
-------

<https://github.com/iluwatar/java-design-patterns/blob/master/abstract-factory/README.md>
* 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
------
Expand Down

0 comments on commit 283a994

Please sign in to comment.