Skip to content

Commit

Permalink
sw_concepts: replace factory example
Browse files Browse the repository at this point in the history
- Draw an own stripped down variant.
- Add slide with a short explanation in front.
  • Loading branch information
BacLuc committed Apr 19, 2024
1 parent 2cf5f49 commit ac140a2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 19 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions topics/sw_concepts/images/factory/factory-bad-case.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@startuml

package domain {

interface Label

class LightLabel

class DarkLabel

Label <|.. LightLabel
Label <|.. DarkLabel
}

package views {
Header --> LightLabel : creates
Header --> DarkLabel : creates

MainView --> LightLabel : creates
MainView --> DarkLabel : creates
}
@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions topics/sw_concepts/images/factory/factory-good-case.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@startuml

package domain {

together {
interface Label

class DarkLabel

class LightLabel
}

class LabelFactory

Label <|.. LightLabel
Label <|.. DarkLabel

LabelFactory -> LightLabel : creates
LabelFactory -> DarkLabel : creates
}

package views {
Header --> LabelFactory: uses
MainView --> LabelFactory: uses
}

@enduml
33 changes: 14 additions & 19 deletions topics/sw_concepts/sw_concept_slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,30 +323,25 @@ Design Patterns

<https://github.com/iluwatar/java-design-patterns>

Factory (method)
Factory
-------

<https://github.com/iluwatar/java-design-patterns/blob/master/factory-method/README.md>
* Alias: Factory Method, Simple Factory
* Use Case:
* Logik für die Erstellung eines Objekts kapseln und vereinheitlichen.
* Wissen um konkrete Implementationen eines Interfaces zentralisieren.

von [Java Design Patterns/Factory](https://github.com/iluwatar/java-design-patterns/tree/07663ce2bdd46ca4697307068b9eb0d4c8888ead/factory)

Factory (method) Beispiel
Factory Beispiel: vorher
------

```python
class CasiceConfigurationFactory:
def create(config):
if not config.is_casice_available():
return CasiceConfiguration.not_available()

if config.get_casice_host_override():
return CasiceConfiguration.with_host(Observable.just(config.get_casice_host_override()))

return CasiceConfiguration.with_host(
RetryUntilSuccess.create(
CasiceHostSupplier(config.get_casice_network_interface()),
Fibonacci.create(60).map(lambda i: 1000 * i)
)
)
```
![Factory Beispiel: vorher](images/factory/factory-bad-case.png){width=78%}

Factory Beispiel: nachher
------

![Factory Beispiel: nachher](images/factory/factory-good-case.png)

AbstractFactory
-------
Expand Down

0 comments on commit ac140a2

Please sign in to comment.