You are on page 1of 67

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 16: Advanced Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyen Doan Minh Hieu Student ID GCD 210003

Class GCD 1102 Assessor name Nguyen Van Loi

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.

Student’s signature Hieu

Grading grid

P3 P4 M3 M4 D3 D4
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

Signature & Date:


Table of Contents
INTRODUCTION .........................................................................................................................................6
CHAPTER 1: LO3 Implement code applying design patterns .....................................................................6
I. Scenario ...................................................................................................................................................... 6
II. Diagram ...................................................................................................................................................... 9
III. Usecase Diagram ................................................................................................................................... 11
IV. Build an application derived from UML class diagrams.(P3) .................................................................. 13
1. Introduce UML, meaning of using UML ................................................................................................................ 13

V. C# Code implements ................................................................................................................................. 15


1. Code..................................................................................................................................................................... 15
2. Result of code ...................................................................................................................................................... 26

VI. After implementing the OOP code=>you realize that there are things to change that need to be added
in your system=>now need to expand the sys- tem=>need to be more optimized=>use Design Pattern ......... 31
VII. Introduce types of design patterns ....................................................................................................... 32
VIII. A final version of the UML class diagram based on chosen scenario which has potential of using Design
Pattern with detailed explanation on how it could solve the scenario. The final class diagram must contain at
least 5 classes. .................................................................................................................................................. 34
IX. Develop code that implements a design pattern for a given purpose.(M3) .......................................... 35
1. Compare between the class diagram before using Design Pattern and after using Design Pattern, to see the
change, see where Design Pattern is used .................................................................................................................... 35
2. Explain why to use that Design Pattern, what it means to use that Design Pattern in the application. ................ 36
3. This section illustrates the complete source code in detail, capturing system functions. ..................................... 36

CHAPTER 2: LO4 Investigate scenarios with respect to design patterns .................................................56


X. Discuss a range of design patterns with relevant examples of creational, structural and behavioral
pattern types.(P4) ............................................................................................................................................. 56
XI. Reconcile the most appropriate design pattern from a range with a series of given scenarios. (M4) ... 62
1. Compare and evaluate the most suitable design pattern with a number of design patterns from defined
scenarios. ..................................................................................................................................................................... 62

CRITICAL EVALUATION ............................................................................................................................66


CONCLUSION ...........................................................................................................................................66
References ..............................................................................................................................................67
Figure 1: Diagram .................................................................................................................................................... 9
Figure 2: Code Person ........................................................................................................................................... 15
Figure 3: Code Student .......................................................................................................................................... 15
Figure 4: Code UnversityClass................................................................................................................................ 16
Figure 5: Code Lecturer ......................................................................................................................................... 16
Figure 6: Input function ......................................................................................................................................... 17
Figure 7: Update function...................................................................................................................................... 18
Figure 8: Sort function ........................................................................................................................................... 19
Figure 9: Search function....................................................................................................................................... 19
Figure 10: Delete function ..................................................................................................................................... 19
Figure 11: Ability function ..................................................................................................................................... 20
Figure 12: Show function....................................................................................................................................... 20
Figure 13: Menu .................................................................................................................................................... 21
Figure 14: Lecturer menu ...................................................................................................................................... 21
Figure 15: Case in Lecturer Menu 1 ....................................................................................................................... 22
Figure 16: Student menu ....................................................................................................................................... 23
Figure 17: Case in Student Menu 1 ........................................................................................................................ 24
Figure 18: UniversityClass menu............................................................................................................................ 25
Figure 19: Case in UniversityClass Menu................................................................................................................ 25
Figure 20: Case 4 in Menu ..................................................................................................................................... 26
Figure 21: Main Menu ........................................................................................................................................... 26
Figure 22: Menu of Manage Lecturer .................................................................................................................... 26
Figure 23: Add Lecturer ......................................................................................................................................... 27
Figure 24: Update Lecturer .................................................................................................................................... 27
Figure 25: Search Lecture by name ........................................................................................................................ 27
Figure 26: Delete Lecturer ..................................................................................................................................... 28
Figure 27: Back menu option ................................................................................................................................. 28
Figure 28: Menu of Manage Student ..................................................................................................................... 29
Figure 29: Sort mark option ................................................................................................................................... 29
Figure 30: Menu of UniversityClass ....................................................................................................................... 29
Figure 31: Add Student .......................................................................................................................................... 30
Figure 32: View class list........................................................................................................................................ 30
Figure 33: Search class by ClassID .......................................................................................................................... 30
Figure 34: When using Design Pattern ................................................................................................................... 31
Figure 35: Class diagram for the system ................................................................................................................ 35
Figure 36: Diagram without adding Design Pattern ................................................................................................ 36
Figure 37: Create Person class ............................................................................................................................... 37
Figure 38: Create Student class ............................................................................................................................. 38
Figure 39: Create ManageStudent class 1 .............................................................................................................. 38
Figure 40: Create ManageStudent class 2 .............................................................................................................. 39
Figure 41: Create ManageStudent class 3 .............................................................................................................. 40
Figure 42: Create Lecturer class ............................................................................................................................. 41
Figure 43: Create ManageLecturer class 1 ............................................................................................................. 42
Figure 44: Create ManageLecturer class 2 ............................................................................................................. 43
Figure 45: Create ManageLecturer class 3 ............................................................................................................. 44
Figure 46: Create ManageLecturer class 4 ............................................................................................................. 45
Figure 47: Create UniversityClass .......................................................................................................................... 46
Figure 48: Create ManageUClass 1 ........................................................................................................................ 47
Figure 49: Create ManageUClass 2 ........................................................................................................................ 48
Figure 50: Create Program class 1 ......................................................................................................................... 49
Figure 51: Create Program class 2 ......................................................................................................................... 50
Figure 52: Create Program class 3 ......................................................................................................................... 51
Figure 53: Create Program class 4 ......................................................................................................................... 52
Figure 54: Main Menu ........................................................................................................................................... 53
Figure 55: Choose wrong ....................................................................................................................................... 53
Figure 56: Add a successful lecturer ...................................................................................................................... 53
Figure 57: Update lecturer .................................................................................................................................... 54
Figure 58: Search Lecturer by name ...................................................................................................................... 54
Figure 59: View Lecturer List ................................................................................................................................. 54
Figure 60: Delete lecturer success ......................................................................................................................... 54
Figure 61: Add a successful student ....................................................................................................................... 55
Figure 62: Sort student follow mark ...................................................................................................................... 55
Figure 63: View class list........................................................................................................................................ 55
Figure 64: Search class by ClassID .......................................................................................................................... 56
INTRODUCTION

We recently joined a software development company to help a university improve student and
faculty management. It was our responsibility to address this by illustrating the importance of UML
diagrams in OOAD and the use of Design Patterns.

As a result, we applied the student management object-oriented analysis and design to this task to
describe the characteristics of the object-oriented programming model. This student management
program exhibits a number of OOP traits (such as: encapsulation, inheritance, polymorphism,
overriding, overloading, etc.). The audience will next be introduced to certain design patterns by way
of real-world examples; the related patterns are then shown in UML class diagrams. Let's find out in
this assignment!

CHAPTER 1: LO3 Implement code applying design patterns


I. Scenario

We are creating a student management system for FPT Academy International based on the
scenario. The information below includes the system requirements:
II. Diagram

We must now determine which classes, interfaces, and relationships will be used in the system after
determining the actual functions that will be used to handle the targets. And in order to determine
those, I created the following Class Diagram, one of the most important diagrams of the structure
and interrelationships of the software's constituent parts.

Figure 1: Diagram

 As you can see in the diagram, there are 4 main classes (UClass, Student, Lecturer, Person)
and their relationship is also well defined with functions.
Name Type Description Relationship

Person Class Include the following object (students and Relationship of


lecturers) properties: ID, Name, Date of Birth, generalizations:
Address and Email along with the scenario's inherited by "Student"
conditions and "Lecturer"

Student Class Include attributes such as: ClassID, Mark, Generalization


Ability and ClassName with conditions in the relationship:
scenario.
inherit from "Person".
Dependency
Relationships: with

"Manage Student "

Lecturer Class Include attributes such as: Dept with Generalization


conditions in the scenario. relationship:

inherit from "Person".


Dependency
Relationships: with

"Manage Lecturer "

UniversityClass Class Class Class has the same attribute ClassID, Dependency
ClassName with Student class, so it has a Relationships:with
one-to-many relationship “Manage Class”

ManageStudent Class Includes "Student" functions and data Relationships of


Composition: with
"Student"

ManageLecturer Class Includes "Lecturer" functions and data Relationships of


Composition: with
"Lecturer"

ManageClass Class Includes "UClass" functions and data Relationships of


Composition: with
"UClass"
III. Usecase Diagram

We must create a use-case diagram—a visual representation of how system users can interact with
the system through its features—in order to give a concise overview of what the system is capable
of. Consequently, and in light of the information provided above, the following use-case diagrams are
possible.

 As you can see, using the following functions, the manager will manage them all: Add new
students, View all students, Search students by ID, Update students, Delete students by ID,
Sort by mark, Sort by ability, ShowstudentClass and Back to Main Menu.
 Customers can only View All Students, Search Students by ID, Sort by mark and Back to Main
Menu
 As you can see, using the following functions, the manager will manage them all: Add
new Lecturer, View all the lecture, Search the Lecturer by ID, Update Lecturer, Delete
the Lecturer by ID and Return to Main Menu.
 Customers can only View All Lecturers, Search lecturer by ID and Back to Main Menu
 As you can see, the administrator will manage the class and the customer has access to the
following functions:: View all available classes in the university, Search for classes by ID to see
which students study in that class, and Back to the Menu main.

IV. Build an application derived from UML class diagrams.(P3)


1. Introduce UML, meaning of using UML
 Introduce UML

Software system specification, visualization, construction, and documentation are all done using
the UML (Unified Modeling Language). System designs can be written using UML and can include
ideas like business processes and system functionalities. It is beneficial for declarative languages,
database schemas, and reusable program parts in particular. Rational Rose and numerous other
organisations collaborated to create UML, which quickly established itself as one of the standard
languages for creating object-oriented software systems. It is a deserving replacement for
modeling languages like Booch, OOSE/Jacobson, OMT, and numerous others.

In UML, there are 9 diagrams that are:

 Class Diagram

The foundation of almost all object-oriented techniques, including UML, is a class diagram.
They describe the system's static structure.

 Package Diagram

Class diagrams are gathered in a package diagram. Package diagrams define the relationships
between packages, where packages are collections of interconnected system components.
 Function Chart

Use case diagrams provide an overview (top-down) of how the system is used as well as an
outside view of the system.

 Interactive Charts

The Collaboration Diagram shows how the objects in the current model interact or have
structured relationships with one another. Objects, linkages, and messages are included in
the collaboration diagram. Use the model as your main tool for defining how the system
interacts and behaves.

 Progress Chart

Sequence diagram depicts the interaction of layers in temporal sequence. These models are
associated with the case method. The sequence diagram shows you step-by- step the events
that occur in the case method. This diagram is the best way to analyze and design the system
because it is quite simple and easy to understand. This is a small example describing a process
that serves to press the elevator button.

 State chart Diagram

You use a State chart Diagram that describes the actions of individual classes and objects,
describing the sequence of states the objects will go through.

 Activity Diagram

Activity Diagrams are used to depict processes and the order in which various steps must be
taken. Because they show how work flows from one activity to the next and from one activity
to a state, they resemble flowcharts. It helps to understand the entire process of the activity
when you design an activity diagram. When describing parallel processes or certain
interactions in a use case, it is quite helpful.

 Component Diagram

We can see the actual model physically thanks to the component diagram. It demonstrates to
us the structure and connections between executable, binary, and source code components
of software.

 Deployment Diagram
The nodes, components, and connections in the system's physical resources are all described
in deployment diagrams. Each model has a single deployment diagram that depicts the
relationship between the procedures and hardware.

 Meaning of using UML

The meaning of using UML is to help people create diagrams from simple to complex, helping
users design an information extremely quickly and accurately as desired.

V. C# Code implements
1. Code
 Person

Figure 2: Code Person

 Student

Figure 3: Code Student


 UniversityClass

Figure 4: Code UnversityClass

 Lecturer

Figure 5: Code Lecturer

Lecturer class and Student class inheritance from Person class, two class have the same objects are ID,
Name, Date of Birth, Email, Address.
Figure 6: Input function

Users can add students to the student list by using the "input function" to submit their details. This
functionality is the same in the Lecturer class.
Figure 7: Update function

By using this function, a user who previously entered a student or lecturer can update or modify part of
their previously entered information. However, the system will print "Student/ Lecturer have ID = (user
input) not valid" if the list of students or lecturers lacks a student or lecturer name similar to the one
entered by the user. In lecturer class, this function is the same.
Figure 8: Sort function

Since students receive grades, another function called "sort function" appears in the classroom. With this
function, students' scores are sorted from low to high.

Figure 9: Search function

If the student or lecturer has the same name as the one entered by the user and they are listed as such,
the system will print "not found" if they are not. In lecturer class, this function is the same.

Figure 10: Delete function

When the user enters their ID, this function will delete a student or lecturer. In lecturer class, this
function is the same.
Figure 11: Ability function

When a user enters a mark for a student in a class, the system will sort the student according to P, M,
and D. This function from the University of Greenwich.

Figure 12: Show function

This feature prints all student/lecturer information from the system to the screen. In lecturer class, this
function is the same.
Figure 13: Menu

I choose to use while for this menu because it has three options: 1. Manage Lecturer, 2. Manage
Student, 3. University Class and 3. Exit. As a result, this function will display everything.

Figure 14: Lecturer menu

Case 1: Manage Lecturer

This example has five CRUD options, and the last one is "Back to main menu," will return the menu when
the user enters six.
Figure 15: Case in Lecturer Menu 1

Case 2: Manage Student

In order to develop and maintain the system, I choose between 6 scenarios, which correspond to 6
alternatives. If the user enters a number other than one between 1 and 6, the system prints "Invalid
choice. Please try again".
Figure 16: Student menu

Similar to a lecturer's menu, this one will include six CRUD selections as well as a "sort mark" and a "back
to main menu" option.
Figure 17: Case in Student Menu 1

Case 3: University Class

In this menu there are 3 options, you can choose option 1 to see the list of classes available in the school.
When you choose option 2 you can see the students studying in that class.
Figure 18: UniversityClass menu

Figure 19: Case in UniversityClass Menu


Case 4: Exit

In the menu there are 3 options, if you enter another from 1 to 3, the message "Invalid choice. Please try
again."

Figure 20: Case 4 in Menu

2. Result of code

Figure 21: Main Menu

Case 1: Manage Lecturer

Figure 22: Menu of Manage Lecturer


Figure 23: Add Lecturer

Figure 24: Update Lecturer

Figure 25: Search Lecture by name


Figure 26: Delete Lecturer

Figure 27: Back menu option


Case 2: Manage Student

The functions of the Student class are similar to the Lecturer class

Figure 28: Menu of Manage Student

Figure 29: Sort mark option

Case 3: UniversityClass

Figure 30: Menu of UniversityClass


Before you choose option 2 UniversityClass, you need to add a student.

Figure 31: Add Student

Then, you choose option 1, the program will give a list of ClassID and ClassName available in the
university that I assigned before.

Figure 32: View class list

To option 2, you just need to search for ClassID, the program will give a list of student names, emails,
classes of students in that class.

Figure 33: Search class by ClassID


VI. After implementing the OOP code=>you realize that there are things to change that need to
be added in your system=>now need to expand the sys- tem=>need to be more
optimized=>use Design Pattern

After introducing OOP, we noticed that the UML version needed numerous flaws to be fixed in order
to have a better student management version and for the system to fully and effectively address the
student management problem.

And here is the version after I applied the Design Pattern to my project

Figure 34: When using Design Pattern


VII. Introduce types of design patterns
 What are design patterns?

Design patterns are reused, optimized complete solutions to frequent software design issues we
go with on a daily basis. This is a collection of problems that have been considered and resolved
in a particular circumstance.

 Design patterns do what?

Programmers can apply this solution to solve similar problems. The problems you face may be
your own to come up with a solution, but it may not be optimal.

You must realize that it is not language-specific. Most computer languages support design
patterns. By giving you solutions in object-oriented programming (OOP), it assists you in finding
the best answers to challenges.

 Why use Design Patterns?

Making our products more changeable, upkeep-friendly, and versatile.

The alteration of requirements is one thing that constantly occurs in software development. The
system is currently expanding, new features are being added, and performance needs to be
adjusted.

Design patterns offer software engineering challenges optimized, tested solutions. By offering
tested models and development models, the generic solutions aid in accelerating the creation of
software.

Design patterns are the approach to help you solve the problem instead of looking for a time-
consuming solution yourself when you are having any difficulties with already solved challenges.

Help programmers can easily comprehend other people's code (for example, the relationships
between modules). The team can quickly and easily communicate with one another to complete
the job.

 When to use Design patterns?

We can spend less time and effort coming up with solutions to issues that have previously been
resolved if we employ design patterns. Software that uses design patterns runs more efficiently,
is simpler to oversee the operation process, is easier to update and maintain, etc.

The design pattern's drawback, however, is that it is an area that is consistently challenging and
somewhat abstract. It's not difficult to understand the requirement for a design pattern when
you're starting to write new code from scratch. It is more challenging to use the design pattern on
outdated code, though.

Another issue we will have while utilizing the existing design patterns is the product's
performance (code, for instance, will run slowly). Before touching the source code, make sure
you are familiar with how it functions overall. Depending on how complicated the code is, this
could be simple or difficult.

Right now, we use a lot of design patterns in our programming. It's time to incorporate a design
pattern into the system if you frequently download and install specific libraries, packages, or
modules.

 What do you need to learn Design Pattern?

Design patterns apply the four OOP principles of inheritance, polymorphism, abstraction, and
encapsulation as they are the foundation of object-oriented programming.

Because it is very important, understand and use the two concepts interface and abstraction.

Think purely OOP and don't use structural reasoning.

 Classify

The system of design patterns is divided into 3 groups: Creational group (5 patterns), Structural
group (7 samples) and Behavioral group (11 patterns).

Creational Patterns

 Abstract Factory
 Builder
 Factory
 Prototype
 Singleton

Structural Patterns

 Adapter
 Bridge
 Composite
 Decorator
 Facade
 Flyweight
 Proxy
Behavioral Patterns

 Chain of responsibility
 Command
 Interpreter
 Iterator
 Mediator
 Memento
 Observer
 State
 Strategy
 Template method
 Visitor

When managing students and utilizing Design patter to aid in problem solving, these are some
challenging situations:

The memory will be overloaded, the data will be very chaotic, and it will be challenging to
manage them, for instance, if we manage pupils of a school that will include a lot of data and they
will be different and highly complex.

We can manage the code more effectively, simply, and efficiently for managers and users by
using Design patter.

VIII. A final version of the UML class diagram based on chosen scenario which has potential of
using Design Pattern with detailed explanation on how it could solve the scenario. The final
class diagram must contain at least 5 classes.

After analyzing and choosing a design pattern, I chose the Factory method Design Pattern for this
scenario. The content is detailed in the image below
Figure 35: Class diagram for the system

 Person

Person class declares common properties such as: ID, Name, Email, Address.

 Student

In the student class, I declare variables: Student ID, Student Name, Student Email, Student
Address, Student ClassID, Student ClassName, Student Mark and Student Ability.

 Lecturer

In the lecture class, I declare variables: Lecturer ID, Lecturer Name, Lecturer Email, Lecturer
Address, Department of Lecturer

 Uclass

In the Uclass class, I declare variables: ClassID, ClassName.

IX. Develop code that implements a design pattern for a given purpose.(M3)
1. Compare between the class diagram before using Design Pattern and after using Design
Pattern, to see the change, see where Design Pattern is used

Before using Design Pattern for my project, I created a diagram that was missing a lot of features.

And here is the diagram without using Design Pattern


Figure 36: Diagram without adding Design Pattern

2. Explain why to use that Design Pattern, what it means to use that Design Pattern in the
application.

I use that Design Pattern for my project because when I write code, my lines of code are very messy
so I applied Factory method calculation to my project because Factory method helps me to manage
and organize my code very efficiently.

3. This section illustrates the complete source code in detail, capturing system functions.
 Code Details

ManageStudent.cs class to store student information.

ManageStudent.cs class contains methods like import students, update students by ID, Delete
students by ID, find students by name, Sort student scores from low to high, show list of
students.

Student.cs class contains student private methods like ClassID, Mark, Ability and ClassName.
Create Person class

Figure 37: Create Person class

Create student management function

Create a student management screen containing the following information:

The fields correspond to the student's attributes.

 Add
 Update
 Delete
 Search
 Sort student folow mark
 View student list
 Back to main menu

This class is to store information for each student.


Figure 38: Create Student class

Figure 39: Create ManageStudent class 1


Figure 40: Create ManageStudent class 2
Figure 41: Create ManageStudent class 3
Create lecturer management function

Create a lecturer management screen containing the following information:

The fields correspond to the lecturer’s attributes.

 Add
 Update
 Delete
 Search
 View student list
 Back to main menu

This class is to store information for each lecturer.

Figure 42: Create Lecturer class


Figure 43: Create ManageLecturer class 1
Figure 44: Create ManageLecturer class 2
Figure 45: Create ManageLecturer class 3
Figure 46: Create ManageLecturer class 4
Create UniversityClass management function

Create a UniversityClass management screen containing the following information:

The fields correspond to the attributes.

 Search
 View student list
 Back to main menu

This class is to store information for UniversityClass.

Figure 47: Create UniversityClass


Figure 48: Create ManageUClass 1
Figure 49: Create ManageUClass 2
Create a Program class to make Student, Lecturer, University Class menus

Figure 50: Create Program class 1


Figure 51: Create Program class 2
Figure 52: Create Program class 3
Figure 53: Create Program class 4
 Capturing system functions.
 Lecturer

Figure 54: Main Menu

When you press other numbers from 1 to 4, the program will display the message "Invalid choice. Please
try again"

Figure 55: Choose wrong

When you press 1 select Manage Lecturer. Then select 1 to add lecturer and enter the information. And
it will show "Add successful !".

Figure 56: Add a successful lecturer

When you press 2 to update lecturer, enter what information you need to update. For example, I'm
trying to update the name "hieu" to "minh".
Figure 57: Update lecturer

When you want to find the information of the lecturer, press 4 and enter the name of the lecturer. The
program will display the information of the lecturer you want to find.

Figure 58: Search Lecturer by name

When you want to see all the lecturer list press 5.

Figure 59: View Lecturer List

When you want to delete a lecturer, press 3 and enter the lecturer ID.

Figure 60: Delete lecturer success


 Student

When you press 2 select Manage Student. Then select 1 to add student and enter the
information. And it will show "Add successful !".

Figure 61: Add a successful student

When you press 5 to sort student scores, the program will list out student information from low to high.

Figure 62: Sort student follow mark

 UniversityClass

When you press 3 in the main menu, then select 1, a program that will list out the list of classes
available in the university.

Figure 63: View class list


When you want to search for students studying in a certain class, press the number 2, then enter ClassID,
the program will display a list of students in that class.

Figure 64: Search class by ClassID

CHAPTER 2: LO4 Investigate scenarios with respect to design patterns


X. Discuss a range of design patterns with relevant examples of creational, structural and
behavioral pattern types.(P4)

Creational pattern types (at least 3 patterns)

Pattern Class Diagrams Short Explanation / Explain how the


Name pattern works

Factory The Creator class is an abstract class or


Method interface containing factoryMethod() and
anOperation() methods.

The ConcreteCreator class is a subclass of


Creator and implements the
factoryMethod() method to create a
concrete instance of Product.

The Product class is an abstract class or


interface that contains methods and
properties that concrete subclasses (like
ConcreteProduct) will implement.

The ConcreteProduct class is a subclass of


Product and implements methods and
properties specific to the Product object.
Singleton The SingleObject class represents a single
object in the entire system. It has an
instance property to store the unique
object and methods like singleObject()
(constructor) and getInstance() to return
the single object.

The getInstance() method checks if a


SingleObject has been created. If not, it will
create a new object and store it in the
instance property, then return that object.
If it already exists, it will directly return that
object.

SingletonPatternDemo class is a demo class


containing main() method. In the main()
method, we use the getInstance() method
to get the SingleObject object and call its
showMessage() method to display the
message.

Prototype The Interface Prototype class is an interface


containing a clone() method. This interface
represents objects that are able to clone
themselves.

The ConcretePrototype1 and


ConcretePrototype2 classes are two
concrete classes that implement the
Interface Prototype interface and provide
an implementation for the clone() method.
They perform the process of copying
themselves to create a new copy.

The Client class is a class that uses the


Prototype model. It hooks through the
Interface Prototype interface and uses the
clone() method to clone objects.
Behavioral pattern types (at least 3 patterns)

Pattern Class Diagrams Short Explanation / Explain how the


Name pattern works

State Context: The object that holds internal


design state and needs to switch behaviors
pattern based on that state. Polymorphism will
be used in statedependent methods
instead of case statements.

State : an interface that contains state-


dependent operations for the Context
object.

Concrete States: concrete


implementations of State. The Context
object can swap these different
implementations at runtime to choose
its behavior.

This is less explanation than usual


because I think the diagram of this
pattern is self- explanatory.

Strategy The Strategy class is an interface


Pattern containing a doOperation() method
with an int return type. This is an
abstract method that describes an
operation.

The OperationAdd,
OperationSubstract and
OperationMultiply classes are
subclasses of Strategy and implement
the doOperation() method. Each class
represents a specific type of operation,
e.g. addition, subtraction,
multiplication.
The Context class is a class that holds a
Strategy object and uses it to perform
an operation. The Context class has a
strategy property to store a Strategy
object and an executeStrategy()
method to perform an operation
based on the set Strategy.

The StrategyPatternDemo class is a


demo class containing the main()
method. In the main() method, we
create a Context object, set a specific
Strategy (e.g. OperationAdd,
OperationSubstract,
OperationMultiply), and call the
executeStrategy() method to perform
the corresponding operation.

Iterator The Container class is an interface


Pattern containing the getIterator() method,
which returns an Iterator object. This
interface represents a collection of
elements and provides a way to
sequentially access the elements in the
set.

The Iterator class is an interface that


contains a hasNext() method that
checks if there is a next element in the
set, and next() returns the next
element in the set. This interface
represents a place in the set and
provides a way to access the elements
sequentially.

The NameRepository class is a class


that implements the Container
interface and stores a name array
containing the elements. It provides
the getIterator() method to return an
Iterator object for sequential access of
the elements in the name array.

The NameIterator class is a class that


implements the Iterator interface and
provides implementations for the
hasNext() and next() methods. It
traverses the elements in the
NameRepository's name array and
provides a way to sequentially access
those elements.

The IteratorPatternDemo class is a


demo class containing the main()
method. In the main() method, we
create a NameRepository object, use
the getIterator() method to get an
Iterator object, and then use the
Iterator to retrieve the elements in the
collection and display them.
Structural pattern types (at least 3 patterns)

Pattern Class Diagrams Short Explanation / Explain how the pattern works
Name

Bridge Abstraction: the heart of the bridge design pattern


Pattern and the bottom line It includes a reference to the
implementer.

Refined Abstraction: Finer details are taken one level


below when abstraction is extended. Better conceal
divisional elements.

Implementer: It defines the interface for the classes


that implement it. This interface does not have to be
identical to the abstract interface and can be quite
different. Abstraction provides an implementation of
the Executor interface's operations.

Specific Implementation: Implement the performer


mentioned above by providing specific
implementation.

Composite The Employee class represents an employee in a


Pattern company. It has attributes like name (name), dept
(department), salary (salary) and subordinates (list
of dependent employees).

Employee has add() method to add a new employee


to the list of dependent employees, remove() to
remove an employee from the list and
getSubordinates() to get the list of dependent
employees.

The CompositePatternDemo class contains the


main() method, which is a demo class to show how
the Composite Pattern works. In the main() method,
we create Employee objects and build a company
tree by adding and removing employees from other
employees.
Decorator
Employee: perform the task (do Task), join the
Pattern
project (join), and leave the project(terminate).

Team member: report the assigned task, and


collaborate with other members (coordinate with
others).

Team leader: planning (planning), assisting


members in their development (motivating), and
monitoring work quality and time (monitor).

Manager: develop project requirements


(develop project requirements), assign tasksto
members (assign tasks), and monitor project
progress (progress management).

XI. Reconcile the most appropriate design pattern from a range with a series of given
scenarios. (M4)
1. Compare and evaluate the most suitable design pattern with a number of design patterns from
defined scenarios.

There are many different sorts of effective and simple design patterns in Design Pattern for various
projects, including Singleton, Prototype, Factory method, Composite, etc. Each type has distinct
benefits and drawbacks as examples.

Singleton:

Along with the Abstract Factory Pattern, Singleton is a Design Pattern that is categorized under
Creational Design Patterns. You can simply understand that: Singleton is a Design Pattern that
ensures that each class will have only one instance, and provides a global access point for this
instance.
Advantages and disadvantages of Singleton Pattern

Advantages Disadvantages

Single Object: The Singleton Pattern ensures Global State: Using Singleton introduces global
only one instance of the class is created and state into the application, making management
provides global access to that object. This can and maintenance more difficult. Changes made
be useful when there is only one object to on the Singleton object can affect other parts of
handle specific operations, such as database the application, causing side effects and
connections or logging systems. dependencies.

Global Access: Singleton objects are globally Testing and Dependency Injection: Singleton
accessible throughout the application, allowing objects can be difficult to test independently, as
centralized control and coordination of they often depend on global state. This also
resources. makes it difficult to inject dependencies into
Singleton, affecting unit testing and flexibility.

Lazy Initialization: A Singleton object is created Hidden dependencies: Code that uses a
only when it is first requested, rather than being dependency on a Singleton can have implicit
created from scratch. This can improve and tightly bound dependencies, since it
performance and reduce memory consumption assumes the existence of the Singleton object.
if the object is not always used. This makes the code confusing and difficult to
maintain.

Thread-Safe: Singleton objects can be designed Danger of Overuse: Due to the convenience of
to be thread-safe, ensuring that multiple global access, developers may feel tempted to
threads can access the object without overuse the Singleton, leading to the use and
introducing data errors or inconsistencies. abuse of this pattern. This can make the source
code more complex and confusing.
Prototype:

A Design Pattern called the prototype pattern is primarily used to lower the cost of creating objects.
Usually when large scale applications create, update, or retrieve resource-intensive objects.

Advantages and disadvantages of Prototype Model

Advantages Disadvantages

Dynamic Object Creation: The Prototype model Complicated in managing cloned objects: As
allows for dynamic object creation at run time the number of cloned objects increases,
by duplicating existing objects. This provides managing and tracking the relationship between
flexibility in object creation and avoids having to original objects and cloned objects can become
create subclasses or use complex initialization complicated. Changes on an object may not be
logic. reflected in copied objects, resulting in
inconsistencies.

Reduced initialization costs: Creating objects Copying complex objects: Copying objects
from scratch can be expensive in terms of time containing complex data structures, circular
and resources. The Prototype model allows references, or dependencies can be difficult.
creating objects by copying existing objects, This may require implementing custom
which reduces the cost of initialization. replication logic or using serialization
techniques to ensure the integrity of the copied
objects.

Customize the object creation process: Deep or shallow object copying: The Prototype
Prototypes can be customized before being model supports both shallow (shallow) and
copied to create new objects. This allows deep (deep) copying. Shallow copying creates
specific properties or configurations of the copies with shared references to internal
object to be changed, providing more control objects, while deep copying creates copies with
over the object creation process. separate instances of internal objects. Choosing
the right copying strategy can be daunting and
may require additional work.

Encapsulate copy logic: The Prototype model Impact on performance: Depending on the
encapsulates copy logic inside objects. This complexity of the objects being copied and the
eliminates the need for the client to understand replication process, the Prototype model can
the copying process and simplifies the object have a performance cost. Copying large or
creation process. deeply structured objects can be time and
resource consuming.
Factory Method

Factory Method is a design pattern that belongs to the Creational Pattern group in the field of
software development. It provides a way to create objects dynamically and helps avoid direct object
initialization via the "new" keyword.

In Factory Method, we define an object creation method (called "Factory Method") in a parent class
(or interface) and allow subclasses to reimplement this method to create concrete instances. object's
body. Factory Method allows us to create objects without knowing which subclasses are created.
Deciding which subclass to use for object creation takes place at run time.

Factory Method helps to reduce dependencies between source code and concrete classes, provides
extensibility and flexibility in object creation, and ensures Single Responsibility principle in software
design.

Advantages Disadvantages

Flexibility: Factory Method allows to extend and create Increased complexity: Using Factory Method can
objects in a flexible way. By using the Factory Method, increase the complexity of the source code. You need
you can define and create objects of subclasses to create additional classes and methods to
independently, without modifying the original source implement Factory Method and its respective
code. subclasses.

Ensuring Single Responsibility: Factory Method principle The number of classes increases: Each subclass needs
helps to ensure that each class is responsible for its own Factory Method. This can lead to an increase
creating only one specific object. This helps to maintain in the number of layers in the system and increase
the Single Responsibility principle in the design and the complexity of layer management.
increases the modularity of the source code.

Easy extensibility and replacement: By using the Factory Difficulty in debugging: When using Factory Method,
Method, you can easily extend or replace subclasses and debugging can become more difficult. Since object
corresponding objects. You just need to create a new creation is hidden and occurs in the Factory Method,
class that replaces the Factory Method without affecting tracking and error checking can be difficult.
the existing source code.

Encapsulate object creation logic: Factory Method helps Requires understanding of system structure: Using
to encapsulate object creation logic in a single place. Factory Method requires understanding the structure
This makes the source code easier to read, understand, and relationships between classes in the system. This
and maintain. can increase complexity for new developers or source
code readers unfamiliar with the structure.
CRITICAL EVALUATION
After finishing my report, I was able to demonstrate the importance of UML diagrams in OOAD and the
use of Design Patterns in order to grasp the problem. In order to characterize the qualities of the object-
oriented programming model, I also applied student management object-oriented analysis and design to
this assignment. OOP features are demonstrated in this student management program and are shown in
a UML class diagram.

Advancement in programming is awesome! It has helped me to comprehend how the technology around
me functions. This is fantastic and really fascinating.

CONCLUSION
After completing this assignment with your own efforts. During the course of the study, the teacher was
very enthusiastic in teaching and always answered my questions. With the knowledge I have learned, I
have presented very fully the questions raised by the Exercise in a concise, clear and specific way.
Moreover, I am confident that I can self-study and can do advanced programming for business.

During the development, I tried my best to develop the project successfully. Here is my team review:
References
Anon., n.d. [Online]
Available at: https://websitehcm.com/prototype-model-mo-hinh-phat-trien- phan-mem/

Anon., n.d. [Online]


Available at: https://chiasekinang.com/singleton-pattern-la-gi/

Anon., n.d. [Online]


Available at: https://chat.openai.com/

You might also like