Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory vs Singleton #1

Open
Burakkylmz opened this issue Oct 22, 2021 · 2 comments
Open

Factory vs Singleton #1

Burakkylmz opened this issue Oct 22, 2021 · 2 comments

Comments

@Burakkylmz
Copy link

Hi Songul, we already know both singleton and factory design patterns use to create objects. However, I can't decide which one to choose when creating an object. What issues do you think I should consider? How should I decide?

@SongulSYTRK
Copy link
Owner

If you need one instance , you should singleton . This pattern includes single class . Multiple classes must be use one instance , you should use singleton design pattern .

You have more concrete class .We have a lot of classes and you want to create a similar object. I think You have 2 way to reach classes . One of them you should "new " concrete class one by one or you must create factory class. Factory class include object of concrete class . If you use factory class, you can created different more object and same time you have connected loosly coupled with other class. We know that We dont want to strong bond with other class.

@kadir-code
Copy link

@SongulSYTRK
As you mentioned above, only one instance satisfies the needs. Based on that, I can say that singleton is pretty cool for ram management because we don't have to repeatedly create new objects with the "new" keyword to take up ram space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants