Assignment 2 - Advanced Programming
Assignment 2 - Advanced Programming
Assignment 2 - Advanced Programming
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.
Grading grid
P3 P4 M3 M4 D3 D4
Summative Feedback: Resubmission Feedback:
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
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!
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
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”
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.
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.
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.
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.
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
Student
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.
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.
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.
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.
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
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
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
In the menu there are 3 options, if you enter another from 1 to 3, the message "Invalid choice. Please try
again."
2. Result of code
The functions of the Student class are similar to the Lecturer class
Case 3: UniversityClass
Then, you choose option 1, the program will give a list of ClassID and ClassName available in the
university that I assigned before.
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.
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
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.
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.
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.
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.
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.
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
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.
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 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
Add
Update
Delete
Search
Sort student folow mark
View student list
Back to main menu
Add
Update
Delete
Search
View student list
Back to main menu
Search
View student list
Back to main menu
When you press other numbers from 1 to 4, the program will display the message "Invalid choice. Please
try again"
When you press 1 select Manage Lecturer. Then select 1 to add lecturer and enter the information. And
it will show "Add successful !".
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.
When you want to delete a lecturer, press 3 and enter the lecturer ID.
When you press 2 select Manage Student. Then select 1 to add student and enter the
information. And it will show "Add successful !".
When you press 5 to sort student scores, the program will list out student information from low to high.
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.
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.
Pattern Class Diagrams Short Explanation / Explain how the pattern works
Name
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 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/