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 Mar 18, 2024
1 parent 0296bc1 commit 660e3d8
Show file tree
Hide file tree
Showing 5 changed files with 67 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.
26 changes: 26 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,26 @@
@startuml

package domain {

interface Coin

class GoldCoin implements Coin

class CopperCoin implements Coin

class SilverCoin implements Coin

}

package main {
Main --> GoldCoin : creates
Main --> CopperCoin : creates
Main --> SilverCoin : creates
}

package bank {
Bank --> GoldCoin : creates
Bank --> CopperCoin : creates
Bank --> SilverCoin : 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 {

interface Coin

class GoldCoin implements Coin

class CopperCoin implements Coin

class SilverCoin implements Coin

class CoinFactory

CoinFactory -> SilverCoin : creates
CoinFactory -> GoldCoin : creates
CoinFactory -> CopperCoin : creates
}

package main {
Main --> CoinFactory: uses
}

package bank {
Bank --> CoinFactory: 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.

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

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 660e3d8

Please sign in to comment.