Comments (3)
Hello Alexandre,
I am glad you found the explanation of the design patterns useful and thank you for the positive feedback!
Regarding your question about a positive aspect that I mentioned for the Factory Method that "Supports the Open-Closed Principle by allowing the addition of new subclasses without modifying the existing factory class.
" I look a it like this:
We know that the Open-Closed principle states that software entities should be open for extension, but closed for modification.
In the example that you provided by creating a new object WhatsApp
that conforms to the MessageSender
protocol, we need to update the enum MessageType
to contain that new case whatsApp
.
I see this as an extension of the types that the Factory class can support and not a modification to that class because the return will always be a MessageSender
so we are not modifying the end result we are just extending its functionalities to support the creation of new objects.
All the best,
Kevin
from design-patterns-in-ios.
Hello Kevin,
Thank you for your clear answer. I understand much better the O/C principles,
Without modifying the existing factory class.
doesn't mean "forbidden to modify the existing factory class".
It rather means, not making changes that could lead to modifications for customers who use this factory.
That's right ?
Alexandre
from design-patterns-in-ios.
Hello Alexandre,
You're welcome, I am glad that my explanation helped you to better understand the O/C principles.
Yes, that was my intention when I implemented the Factory Design Pattern in this example so you will be able to extend it but that will not affect the other parts of your code that already use it.
from design-patterns-in-ios.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from design-patterns-in-ios.