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 Mar 25, 2024
1 parent f729792 commit 9106b4c
Show file tree
Hide file tree
Showing 5 changed files with 138 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,57 @@
@startuml

class Bootstrap

package views {

class Header

class MainView

}

package components {

interface Label

class LightLabel implements Label

class DarkLabel implements Label

interface Button

class LightButton implements Button

class DarkButton implements Button

}

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,60 @@
@startuml

class Bootstrap

package views {

class Header

class MainView

}

package components {

interface Label

class LightLabel implements Label

class DarkLabel implements Label

interface Button

class LightButton implements Button

class DarkButton implements Button

interface ComponentFactory

class LightComponentFactory implements ComponentFactory

class DarkComponentFactory implements ComponentFactory

LightComponentFactory --> LightLabel
LightComponentFactory --> LightButton

DarkComponentFactory --> DarkLabel
DarkComponentFactory --> DarkButton
}

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, und sicher nicht gemischt.
* Die gleichen If Statements sind tauchen immer wieder an unterschiedlichen Stellen im
Code auf. Man möchte diese If Statements abstrahieren.

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 9106b4c

Please sign in to comment.