Exploring Creational Design Patterns: Factory Method and Singleton
VerifiedAdded on 2025/05/02
|5
|1165
|392
AI Summary
Desklib provides solved assignments and past papers to help students succeed.

Contents
Solution 1:........................................................................................................................................2
Solution 2:........................................................................................................................................3
References........................................................................................................................................5
Solution 1:........................................................................................................................................2
Solution 2:........................................................................................................................................3
References........................................................................................................................................5
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Solution 1:
The creational design patterns concern about the way through which the objects creates and the
reduction in complexities of the objects as well as the instability by creating the objects that will
be in a manner that is controlled. The operator new is considered as the harmful because it will
scatter all the objects on the application and over time it has become more difficult for changing
the implementation as the classes present are coupled very tightly. The creational design pattern
helps to recover from this issue by the decoupling of the client completely from the initialization
process that was actually present. There are four different types of creational design patterns that
are used and the discussion about them is given here:
Singleton: it ensures that at most one instance of the object should be there in the
application.
Factory method: this method is used to create the object of the classes that are related and
without specifying the object which is accurate and need to be created.
Abstract Factory method: This is used to create the family of the objects that are related
and are dependent.
Builder: This is used in order to create objects that are complex and performed by using
the step-by-step approach (Ekanayake and Kodituwakku , 2015).
All these methods are used in the creational design patterns and these design patterns have some
advantages as well as disadvantages (Manoj and Nandakumar, 2016). These are:
Advantages:
These design patterns are the standard solution for the problems related to the
programming problems.
This is the technique that is used to make the code more flexible.
This is the designing structure which achieves a specific purpose.
This is the high-level idiom programming.
These designs are shorthands that are used to describe some aspects of the organization of
the program.
They provide connections with the components of the program.
They are basically the shape of the object model or diagram.
Disadvantages:
Along with the advantages, there are some disadvantages as well and these are they are
very uncertain regarding the understandability of the design.
These design patterns decrease the understandability by addition of the indirection or by
adding the code of line.
The creational design patterns concern about the way through which the objects creates and the
reduction in complexities of the objects as well as the instability by creating the objects that will
be in a manner that is controlled. The operator new is considered as the harmful because it will
scatter all the objects on the application and over time it has become more difficult for changing
the implementation as the classes present are coupled very tightly. The creational design pattern
helps to recover from this issue by the decoupling of the client completely from the initialization
process that was actually present. There are four different types of creational design patterns that
are used and the discussion about them is given here:
Singleton: it ensures that at most one instance of the object should be there in the
application.
Factory method: this method is used to create the object of the classes that are related and
without specifying the object which is accurate and need to be created.
Abstract Factory method: This is used to create the family of the objects that are related
and are dependent.
Builder: This is used in order to create objects that are complex and performed by using
the step-by-step approach (Ekanayake and Kodituwakku , 2015).
All these methods are used in the creational design patterns and these design patterns have some
advantages as well as disadvantages (Manoj and Nandakumar, 2016). These are:
Advantages:
These design patterns are the standard solution for the problems related to the
programming problems.
This is the technique that is used to make the code more flexible.
This is the designing structure which achieves a specific purpose.
This is the high-level idiom programming.
These designs are shorthands that are used to describe some aspects of the organization of
the program.
They provide connections with the components of the program.
They are basically the shape of the object model or diagram.
Disadvantages:
Along with the advantages, there are some disadvantages as well and these are they are
very uncertain regarding the understandability of the design.
These design patterns decrease the understandability by addition of the indirection or by
adding the code of line.

Solution 2:
Figure 1: Check out
Figure 2: Computer Price
Solution:
(a) The best design pattern that is noticed and found useful is the factory method pattern as this
provides the permission to sub-classes for selecting the object type for the creation. Also, it
allows the loose-coupling by removing the bind application specific class in the code. That
indicates the code interact with the abstract class. A factory design pattern is appropriate because
it helps in the maintenance of the order and also helps in the generation of the bills which is
Figure 1: Check out
Figure 2: Computer Price
Solution:
(a) The best design pattern that is noticed and found useful is the factory method pattern as this
provides the permission to sub-classes for selecting the object type for the creation. Also, it
allows the loose-coupling by removing the bind application specific class in the code. That
indicates the code interact with the abstract class. A factory design pattern is appropriate because
it helps in the maintenance of the order and also helps in the generation of the bills which is
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

based on the products or items that are selected (Leavens and Naumann, 2017). Moreover, this
design pattern helps to resolve the issue of defining a separate operation in order to create the
object and this can be done by calling the factory method. So for the above reasons, it is
observed that this is the efficient design pattern.
(b) The two use cases that are designed by using the draw.io are the check out as well as
computer price designs and the use case that is developed is linked with other entities. In the
check out the class diagram, the entity checks out is connected with entities cart, pay screen, the
policy of gifts, computer price, print receipt and buy screen. All these entities have different
attributes. The entity cart is connected with entity gift and items. The items are the aggregation
of different products named as television, books, speakers, etc. And the policy of the gift entity is
connected with the entity gift as the policies applied will be on gifts only.
Another class diagram is of the computer price; the computer price entity contains two different
attributes and is connected with entity items. The two entities named as OverseasComputerPrice,
Localcomputerprice is also connected with the entity Check out. The table computer price is
connected with the table items. On combining these entire attribute, the class diagram is created.
(c) As the selected design patterns are the factory method and it is selected because of the
benefits which this design pattern provide. The first and important reason to select this design
pattern is that this provides the benefit of maintaining the orders that are selected by the
consumers as well as help in the generation of the bills of the items chosen. Another benefit that
this design pattern provides is that it helps in rectifying the issue of defining the operation
separately for creating the object which is performed by the calling of the factory method. So
because of these two major benefits this factory design pattern is chosen and is relevant for the
case study which is provided.
(d) The security pattern selected is the reusability which means the code which can be reused
again. The code which can be reuse is done by the simplest way to getting sure from the very
basic level and every method is performed different task and every class perform the large tasks
also by performing this the reusing of code include the importing the code in the form of package
by itself or by adding it in the file of the package will be more easier and be least ambiguous.
The reuse of the code is highly recommended and it should be a standard which should be
followed by the coders. So these were the merits of the reusability of the code.
And the demerit of the code is that if one code is kept reusing then the optimized code can get
obsolete and provide the least optimization.
Another is the level of abstraction in the java code this provides the code to be optimized and
effective as the extra background information get hide and no unnecessary details are required in
the coding so that makes the code simpler to understand and allow the programmer to make
changes sufficiently.
The demerit of the level of abstraction is that if the programmer needs any background
information then it is not possible by the programmer to get that easily and it is difficult to find
design pattern helps to resolve the issue of defining a separate operation in order to create the
object and this can be done by calling the factory method. So for the above reasons, it is
observed that this is the efficient design pattern.
(b) The two use cases that are designed by using the draw.io are the check out as well as
computer price designs and the use case that is developed is linked with other entities. In the
check out the class diagram, the entity checks out is connected with entities cart, pay screen, the
policy of gifts, computer price, print receipt and buy screen. All these entities have different
attributes. The entity cart is connected with entity gift and items. The items are the aggregation
of different products named as television, books, speakers, etc. And the policy of the gift entity is
connected with the entity gift as the policies applied will be on gifts only.
Another class diagram is of the computer price; the computer price entity contains two different
attributes and is connected with entity items. The two entities named as OverseasComputerPrice,
Localcomputerprice is also connected with the entity Check out. The table computer price is
connected with the table items. On combining these entire attribute, the class diagram is created.
(c) As the selected design patterns are the factory method and it is selected because of the
benefits which this design pattern provide. The first and important reason to select this design
pattern is that this provides the benefit of maintaining the orders that are selected by the
consumers as well as help in the generation of the bills of the items chosen. Another benefit that
this design pattern provides is that it helps in rectifying the issue of defining the operation
separately for creating the object which is performed by the calling of the factory method. So
because of these two major benefits this factory design pattern is chosen and is relevant for the
case study which is provided.
(d) The security pattern selected is the reusability which means the code which can be reused
again. The code which can be reuse is done by the simplest way to getting sure from the very
basic level and every method is performed different task and every class perform the large tasks
also by performing this the reusing of code include the importing the code in the form of package
by itself or by adding it in the file of the package will be more easier and be least ambiguous.
The reuse of the code is highly recommended and it should be a standard which should be
followed by the coders. So these were the merits of the reusability of the code.
And the demerit of the code is that if one code is kept reusing then the optimized code can get
obsolete and provide the least optimization.
Another is the level of abstraction in the java code this provides the code to be optimized and
effective as the extra background information get hide and no unnecessary details are required in
the coding so that makes the code simpler to understand and allow the programmer to make
changes sufficiently.
The demerit of the level of abstraction is that if the programmer needs any background
information then it is not possible by the programmer to get that easily and it is difficult to find
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

the information which is not major but important. So this is why the level of abstraction is
beneficial as well as can cause problems.
References
Leavens, G.T. and Naumann, D.A., 2017, April. An Illustrated Guide to the Model
Theory of Supertype Abstraction and Behavioral Subtyping. In School on Engineering
Trustworthy Software Systems (pp. 39-88). Springer, Cham.
Manoj, H.M. and Nandakumar, A.N., 2016. Constructing Relationship between Software
Metrics and Code Reusability in Object Oriented Design. IJACSA) International Journal
of Advanced Computer Science and Applications, 7(2).
Ekanayake, E.M.N.K. and Kodituwakku, S.R., 2015, August. Consistency checking of
UML class and sequence diagrams. In 2015 8th International Conference on Ubi-Media
Computing (UMEDIA) (pp. 98-103). IEEE.
beneficial as well as can cause problems.
References
Leavens, G.T. and Naumann, D.A., 2017, April. An Illustrated Guide to the Model
Theory of Supertype Abstraction and Behavioral Subtyping. In School on Engineering
Trustworthy Software Systems (pp. 39-88). Springer, Cham.
Manoj, H.M. and Nandakumar, A.N., 2016. Constructing Relationship between Software
Metrics and Code Reusability in Object Oriented Design. IJACSA) International Journal
of Advanced Computer Science and Applications, 7(2).
Ekanayake, E.M.N.K. and Kodituwakku, S.R., 2015, August. Consistency checking of
UML class and sequence diagrams. In 2015 8th International Conference on Ubi-Media
Computing (UMEDIA) (pp. 98-103). IEEE.
1 out of 5
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.