Skip to content

Add Simple Factory Pattern implementation - #1516

Merged
iluwatar merged 11 commits into
iluwatar:masterfrom
samilAyoub:add-simple-factory
Sep 6, 2020
Merged

iluwatar merged 11 commits into
iluwatar:masterfrom
samilAyoub:add-simple-factory

Conversation

@samilAyoub

Copy link
Copy Markdown
Contributor

Java source code demonstrate simple factory design pattern.

relates to : #1477

@iluwatar iluwatar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md is missing

Comment thread pom.xml Resolved
- Change the name to factory is done
- Local variable type inference is used
@samilAyoub

samilAyoub commented Sep 3, 2020 •

Copy link
Copy Markdown
Contributor Author

@iluwatar I don't know why urm-maven-plugin generates factory.urm.puml but does not generates factory.urm.png?

@samilAyoub
samilAyoub requested a review from iluwatar September 3, 2020 22:03
@ravening

ravening commented Sep 4, 2020

Copy link
Copy Markdown
Contributor

One suggestion which I can say is to use Lambda expressions instead of using switch cases to generate Cars.
You can refer to an example in https://github.com/ravening/Lambda-Expressions_java/tree/master/designpatterns/rv/factory

Comment thread factory/pom.xml Resolved
- Using lambda expression to create cars
- Using spaces instead of tabs in pom.xml
@iluwatar

iluwatar commented Sep 5, 2020

Copy link
Copy Markdown
Owner

@iluwatar I don't know why urm-maven-plugin generates factory.urm.puml but does not generates factory.urm.png?

It doesn't, the image needs to be created by hand. See https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

Comment thread factory/README.md Resolved
Comment thread factory/README.md Resolved
Comment thread factory/README.md Outdated
Comment on lines +125 to +131
## Applicability

Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it.

## Disadvantages:

The code becomes more complicated than it should be.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rephrase this part a bit so that there is ##Applicability section and under it Pros and Cons.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally please add a class diagram.

- Adding class diagram
- Adding Pros and Cons
- replace "" with ''
@samilAyoub
samilAyoub requested a review from iluwatar September 5, 2020 17:39
Comment thread factory/README.md

**Programmatic Example**

We have an interface 'Car' and tow implementations 'Ford' and 'Ferrari'.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We have an interface 'Car' and tow implementations 'Ford' and 'Ferrari'.
We have an interface `Car` and tow implementations `Ford` and `Ferrari`.

Comment thread factory/README.md Resolved
Comment thread factory/README.md
## Applicability
Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it.

## Pros

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Pros
Pros

Comment thread factory/README.md
* Allows keeping all objects creation in one place and avoid of spreading 'new' key value across codebase.
* Allows to writs loosely coupled code. Some of its main advantages include better testability, easy-to-understand code, swappable components, scalability and isolated features.

## Cons

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Cons
Cons

@iluwatar

iluwatar commented Sep 6, 2020

Copy link
Copy Markdown
Owner

Found just minor issues so I'll merge it and push a change after it.

@iluwatar iluwatar added this to the 1.24.0 milestone Sep 6, 2020
@iluwatar
iluwatar merged commit 922c699 into iluwatar:master Sep 6, 2020
@iluwatar

iluwatar commented Sep 6, 2020

Copy link
Copy Markdown
Owner

Many thanks for the new pattern!

@all-contributors please add @samilAyoub for code

@allcontributors

Copy link
Copy Markdown
Contributor

@iluwatar

I've put up a pull request to add @samilAyoub! 🎉

@iluwatar

iluwatar commented Sep 6, 2020

Copy link
Copy Markdown
Owner

@all-contributors please add @ravening for review

@allcontributors

Copy link
Copy Markdown
Contributor

@iluwatar

I've put up a pull request to add @ravening! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants