This pattern comes under the creational patterns which are widely used in programming constructs. In other words, “This Pattern provides the best way to create the Objects. In Factory patterns we create the object of the Class without Exposing the Creation/Instantiation Logic to the User who wants to create the Object and then return the newly Created object using the Common Interface which is inherited by the Class”. Example We take the example of a vehicle. As we know, this vehicle is the superior class of all kinds of the vehicles and they have some common attributes such as engine, wheels, gears etc. Implementation
Conclusion Factory is one of the most useable factory patterns but it is truly depending upon the needs of the Application. If the Application architecture needs it then we use the Factory, otherwise they simply enhance the complexity of the Applications. It is depending upon the needs, like let’s say we have a problem in which we want to cast most of the subclass objects to the Base/Super so we shall prefer to use the Factory. As we kno that the Factory violates the OCP principle of the Object Oriented Paradigm so most developers suggest using the “Class Registration Implementation” which is the good mechanism.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: