You are on page 1of 40

Higher Nationals in Computing

Unit 19: Data Structures and Algorithms


ASSIGNMENT 2

Assessor name: PHAN MINH TAM

Learner’s name: VO NGUYEN DUY NAM


ID: GCS200888
Class: GCS1001B
Subject code: 1649

Assignment due: Assignment submitted:


ASSIGNMENT 1 BRIEF
Qualification BTEC Level 5 HND Diploma in Computing

Unit number Unit 20: Advanced Programming

Assignment title Examine and design solutions with OOP and Design Patterns

Academic Year 2022-2023

Unit Tutor Nguyen Ngoc Thanh

Issue date Submission date

Submission Format:

Format: The submission is in the form of a group written report. This should be written in a concise,
formal business style using single spacing and font size 12. You are required to make use of
headings, paragraphs and subsections as appropriate, and all work must be supported with
research and referenced using the Harvard referencing system. Please also provide a
bibliography using the Harvard referencing system.
Submission Students are compulsory to submit the assignment in due date and in a way requested by the
Tutors. The form of submission will be a soft copy in PDF posted on corresponding course of
http://cms.greenwich.edu.vn/
Note: The Assignment must be your own work, and not copied by or from another student or from
books etc. If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you
must reference your sources, using the Harvard style. Make sure that you know how to reference properly,
and that understand the guidelines on plagiarism. If you do not, you definitely get fail
Assignment Brief and Guidance:
Scenario: You have recently joined a software development company to help improve their documentation of their in-houses
software libraries which were developed with very poor documentation. As a result, it has been very difficult for the company
to utilise their code in multiple projects due to poor documentation. Your role is to alleviate this situation by showing the
efficient of UML diagrams in OOAD and Design Patterns in usages .

Tasks
You and your team need to explain characteristics of Object-oriented programming paradigm by applying Object-oriented
analysis and design on a given (assumed) scenario. The scenario can be small but should be able to presents various
characteristics of OOP (such as: encapsulation, inheritance, polymorphism, override, overload, etc.).
The second task is to introduce some design patterns (including 3 types: creational, structural and behavioral) to audience by
giving real case scenarios, corresponding patterns illustrated by UML class diagrams.
To summarize, you should analyze the relationship between the object-orientated paradigm and design patterns.

The presentation should be about approximately 20-30 minutes and it should be summarized of the team
report.
Learning Outcomes and Assessment Criteria

Pass Merit Distinction

LO1 Examine the key components related to the object-orientated programming paradigm,
analysing design pattern types

P1 Examine the M1 Determine a design pattern D1 Analyse the relationship


characteristics of the object- from each of the creational, between the object-orientated
orientated paradigm as well structural and behavioural paradigm and design patterns.
as the various class pattern types.
relationships.

LO2 Design a series of UML class diagrams

P2 Design and build class M2 Define class diagrams for D2 Define/refine class
diagrams using a UML tool. specific design patterns using a diagrams derived from a given
UML tool. code scenario using a UML tool.
TABLE OF CONTENTS
Introduction...............................................................................................................1
P1. EXAMINE THE CHARACTERISTICS OF THE OBJECT-ORIENTATED PARADIGM AS WELL AS
THE VARIOUS CLASS RELATIONSHIPS:........................................................................1-12
1. OOP General Concepts:..........................................................................................1
2. Class:......................................................................................................................2
3. Object:...................................................................................................................3-5
4. Data Abstraction:...................................................................................................5-6
5. Encapsulation:........................................................................................................6-7
6. Inheritance:............................................................................................................8
7. Polymorphism:.......................................................................................................9
8. Method Overloading:.............................................................................................10
9. Method Overriding:...............................................................................................11
10. Interface:.............................................................................................................12
P2. DESIGN AND BUILD CLASS DIAGRAMS USING A UML TOOL:................................13-31
Scenario:...................................................................................................................13-16
1. Use-Case Diagrams: ...............................................................................................17-27
2. Class Diagrams: .....................................................................................................28-31
REFERENCES...............................................................................................................10
Introduction
Advance programming is a subject that contain all programming language paradigms and Object-
oriented programming is a programming language model organized around the objects rather than
“action” and data rather than logic. Historically, a program has been viewed as a logical procedure that
takes input data, processes it, and produces output data. In this assignment, I have required to develop
software system for my company; however, before that I have to understand the Advance Programming
principles, be able to design pattens and the object-oriented programming solution. Besides, I am going to
examine the key components related to the object-orientated programming paradigm and analyze design
pattern types. Moreover, I also define and design class diagrams for specific design patterns using a UML
tool.
Finally, I will analyze the relationship between the object-orientated paradigm and design patterns,
show fully the results into my report.

P1. EXAMINE THE CHARACTERISTICS OF THE OBJECT-ORIENTATED PARADIGM AS WELL AS


THE VARIOUS CLASS RELATIONSHIPS.
1. OOP General Concepts
Programming languages that use objects are known as "object-oriented programming," or OOPs.
The objective of object-oriented programming is to incorporate real-world ideas like inheritance, hiding,
polymorphism, etc. into computer code. The main objective of OOP is to connect the functions that use
the data and the data itself, ensuring that only that function and no other part of the code can access the
Data.
OOPs Concepts:
+ Class
+ Objects
+ Data Abstraction
+ Encapsulation
+ Inheritance
+ Polymorphism
+ Dynamic Binding
+ Message Passing

1
2. Class
An individual data type is a class. When a class instance is created, its data members and member
functions can be accessed and used. It stands for the collection of traits or operations that all objects of a
particular type share. A class is comparable to an object's blueprint

Code example: New objects are initialized in class constructors. Methods are used to implement the action

Output:

3. Object
2
It is a fundamental building block of Object-Oriented Programming and represents actual physical
entities. A Class is an instance of an Object. No memory is allocated when a class is specified, but it is
allocated when an object is generated, or when the class is instantiated. Objects have identities, states, and
behaviors. Each object has code to alter the data as well as data itself. It is sufficient to know the sort of
message an object accepts and the type of response it returns for objects to communicate with one
another without knowing specifics about each other's data or programming

Example: A class is said to be instantiated when its object is produced. Every instance shares the traits
and behaviors of the class. The states of such properties, or their values, are unique to each object. There is
no limit to how many instances there can be of a single class

Code:

3
4
Output:

4. Data Abstraction
One of object-oriented programming's most fundamental and significant characteristics is data
abstraction. By hiding the implementation or background information and simply revealing the data's core
characteristics to the outside world, this practice is known as data abstraction. Take a look at a man
operating a vehicle in the real world. The man only understands that pressing the accelerators will make
the car go faster and that applying the brakes will make the car stop, but he is unaware of the inner
workings of the car or how the accelerator, brakes, and other driving controls are implemented.
Abstraction is just this.
Example: Take the example of a traditional "form," which
may be found in a computer-aided design
system or gaming simulation. Each shape has a color, size,
and other attributes, and "shape" is the base
type. The circle, square, triangle, and other sorts of shapes
are derived (inherited) from this and may each
have extra traits and behaviors. One can flip some shapes,
for instance. Certain behaviors, such when you try to figure
out a square's area, might be different.

5
Output:

5. Encapsulation
Data wrapped up into a single unit is referred to as
encapsulation. It serves as the link between the code and the
data that it works with. With encapsulation, a class's variables
or data are kept private from other classes and are only
accessible through member functions of the class in which
they were declared. Data-hiding is another name for
encapsulation since it involves keeping a class's data private
from other classes

Code example:
6
Output:

7
6. Inheritance
A crucial OOP tenet is inheritance (Object-Oriented Programming). Inheritance refers to a class's
capacity to inherit traits and properties from another class. The properties of other classes are inherited
when we create a class. Therefore, since properties and functions can be inherited from another class that
already has them, we do not need to write them all by hand when we build a class. The user can reuse code
and lessen its redundancy by using inheritance whenever possible.

Example: The base class in the inheritance example below is called GFG, the derived class is called
GeeksforGeeks, and the driver class is called Sudo
Code:

Output:

7. Polymorphism
Polymorphism refers to the
existence of various forms.
Polymorphism can be simply defined as a
message's capacity to be presented in

8
multiple forms. One person may, for instance, exhibit several different traits at once. A father, a husband,
and an employee are all dual roles that a man plays. Therefore, the same person exhibits diverse behavior
depending on the circumstance. Polymorphism is the term for this
Example: Take the Animal base class, for example, which has a function called animalSound (). Animals
that are descended from pigs, cats, dogs, and birds each have their own unique animal sound (the pig
oinks, while the cat meows).

Output:

8. Method Overloading
Polymorphism is typically implemented by method overloading. It is the capacity to reinterpret a
function in several ways. By specifying two or more functions in a class with the same name, a user can
implement function overloading. The varied method signatures in C# allow for method differentiation. In
9
other words, methods inside the same class can have the same name but distinct parameter lists (i.e., the
number of parameters, their order, and their data types)
+ Based on the quantity and kind of parameters that are supplied to the methods as
arguments, overloaded methods are distinguished.
+ More than one method definition cannot share the same name, order, or argument type.
A compiler error would result.
+ When differentiating the overloaded method, the compiler does not take the return type
into account. However, you are unable to specify two methods with identical signatures but various
return types. A compile-time error will be generated. It is impossible if both methods have the same
parameter types but a different return type.

Code:
Output:

10
9. Method Overrding
When two or more methods share the same name in a piece of
code yet perform distinct tasks from one another, this is referred to as
method overriding. Accordingly, if we interpret the name in its literal
sense, one approach must take precedence over another. Redefining a
base class method in a derived class using the same method signature is
what this idea refers to
One approach Perl uses to provide Run Time Polymorphism is
method overriding. The object that is used to invoke a method will
determine which version of it is executed. If a method is invoked by an
object of a parent class, the method in the parent class will be utilized;
however, if a method is invoked by an object of a subclass, the method in
the child class will be used. In other words, which version of an
overridden method will be executed depends on the type of the object
being referred to, not the type of the reference variable
Code:

Output:

11
10. Interface
Interface can have members that are methods, properties,
events, and indexers, much like a class.
However, interfaces will only include the members' declarations.
The class that either explicitly or indirectly implements the interface will
provide the implementation of its members
+ Interfaces specify what a class must do and not how.
+ Interfaces can9t have private members.
+ By default all the members of Interface are public and
abstract.
+ The interface will always defined with the help of
keyword 8interface8.
+ Interface cannot contain fields because they represent a
particular implementation of data.
+ Multiple inheritance is possible with the help of Interfaces but not with classes.

Code:

Output:

12
P2. DESIGN AND BUILD CLASS DIAGRAMS USING A UML TOOL
Scenario
Due to high market demand, the number of management positions in stores is increasing day by
day, so merchants want software that can handle basic business to reduce their workload. The company
wanted me to create laptop store management software to track products, customers, and employees.
Involves employee and customer information such as id, name, address and phone number. Information
about the product, such as id, name and price. All product management, customer management and
employee management information can be added, edited, deleted, found and viewed all.
Information that will be stored for each customer:

Name Description

Id Customer code: C001

Name Name of customer: Vo Nguyen Duy Nam

Address Address of customer: Dong Thap

Phone Phone of customer: 0836891929

Information that will be stored for each employee:

Name Description

Id Customer code: E001

Name Name of customer: Nguyen Minh Tri

Address Address of customer: Hau Giang

Phone Phone of customer: 0817726472

Information that will be stored for each product:

Name Description

Id Customer code: P001

Name Name of customer: Asus VivoBook

Price Price of product: 1700$

This application must offer functionalities through a menu


13
1. Manage Employee
2. Manage Customer
3. Manage Product
4. Exit
=====================
Please choose:
The application will end when the user selects 6
The program will show a submenu for managing Employee when the user picks option 1:
======== Employee ======
1. Add Employee
2. Update Employee
3. Delete Employee
4. View all Employee
5. Find Employee
6. Back to main menu
======================
Please choose:
The program will show a submenu for managing Customer when the user picks option 2:
======== Customer ======
1. Add Customer
2. Update Customer
3. Delete Customer
4. View all Customer
5. Find Customer
6. Back to main menu
======================
Please choose:
The program will show a submenu for managing Product when the user picks option 3:
======== Product ======
1. Add Product

14
2. Update Product
3. Delete Product
4. View all Product
5. Find Product
6. Back to main menu
======================
Please choose:
For the Employee Management submenu:
+ When the user selects 1, the program prompts the user to enter the information. After that, the
program will validate the input data and if they are valid, the program will add the new employee
to the current employee list.
+ When the user selects 2, the program will let the user enter the id if the list has the user id entered,
the program will prompt the user to update the information of that id.
+ When the user selects 3, the program will let the user enter the id, if the list has the user id entered,
the program will remove that id's information from the list.
+ When the user selects 4, the program will display all the information of each employee in the list.
+ When the user selects 5, the program will let the user enter the id if the list has the entered user id
then the program will display all the information of that id.
+ When the user selects 6, the program returns to the main menu.
For the Customer Management submenu:
+ When the user selects 1, the program prompts the user to enter the information. After that, the
program will validate the input data and if they are valid, the program will add the new customer to
the existing customer list.
+ When the user selects 2, the program will let the user enter the id, if the list has entered the user id,
the program will prompt the user to update the information of that id.
+ When the user selects 3, the program will let the user enter the id, if the list has the user id entered,
the program will remove that id's information from the list.
+ When the user selects 4, the program will display all the information of each customer in the list.
+ When the user selects 5, the program will let the user enter the id if the list has the entered user id
then the program will display all the information of that id.

15
+ When the user selects 6, the program returns to the main menu.
For the Product Management submenu:
+ When the user selects 1, the program prompts the user to enter the information. After that, the
program will validate the input data and if they are valid, the program will add the new product to
the existing product list.
+ When the user selects 2, the program will let the user enter the id, if the list has entered the user id,
the program will prompt the user to update the information of that id.
+ When the user selects 3, the program will let the user enter the id, if the list has the user id entered,
the program will remove that id's information from the list.
+ When the user selects 4, the program will display full information of each product in the list.
+ When the user selects 5, the program will let the user enter the id if the list has the entered user id
then the program will display all the information of that id.
+ When the user selects 6, the program returns to the main menu.

16
1. Use Case Diagram
A UML behavior or dynamic diagram is a use case diagram. Employ case diagrams use actors and
use cases to represent the functionality of a system. Use cases are a collection of tasks, offerings, and
operations the system must handle. A "system" in this context is something that is being created or run,
like a website. The "actors" are individuals or groups acting in certain capacities inside the system
Notations:
+ Actor: A system's interactions with external entities are represented by actors. The actor itself is
not fully modeled by the system because it is external to it. However, the latter may have a
simplified model of the actor in order to design the interactions between an actor and a system.
One typical example of an actor is a system user. Other sorts of actors include external hardware,
such as a sensor, software systems that are being integrated with the existing system (for example,
a network protocol, a database system, a file system), and so on.
+ Use Case: A use case indicates a feature that the system is anticipated to implement (usually a
need). Other than its distinct name, a use case's details are not physically reflected in the diagram;
instead, they are described in use case narratives. A use case may be divided into multiple use
cases and connected by > or > relationships depending on the application domain and the
designer's decision (described later in this document). Typically, use cases are started by the main
actors. Through a series of use cases, the system makes use of secondary actors like a database. A
two-way communication is represented by the association between a use case and an actor. As a
result, if a primary actor initiates a use case, the latter must receive a response. Similar to this, if a
secondary actor and a use case are associated, the communication begins with the use case, and the
secondary actor is anticipated to reply to the initiation.
+ Generalization: This illustrates a connection between the actors or use cases. The actor (or use
case) at the tail end of the arrow (attached to the base of the triangle) is a customized version of the
actor (or use case) at the other end if two actors are related through this connection. The actor (or
use case) at the base end, which is attached to the triangle's base, is occasionally referred to as a
specialized variation of the actor (or use case) at the other end. The generalization means that the
specialized version includes all of the features of the general version and possibly even more. Take
note that there is no communication between the two actors (or two use cases) connected by the
generalization relationship. In other words, the designer simply makes use of this relationship to
streamline the implementation's coding.
17
+ Associating: This shows a two-way dialogue between an actor and a use case, and is thus a binary
relation. Every use case that a primary actor initiates must respond back to the actor because it is a
two-way communication. Similar to this, every time a use case initiates contact with a secondary
actor, the secondary actor is required to respond to the use case. Information about cardinality, or
how many actors or use cases are involved in the communication, may be included in an
association. For further information on cardinality, see the rules below.
+ Include: This unique arrangement between the two use cases. When a use case A includes a
related use case B, the effort of implementing A depends on the implementation of B. B, on the other
hand, can stand on its own. Therefore, B is not required to be familiar with A. Any other use case
may also include B.
+ Extend: This unique relationship between two use cases is yet another unusual type. The
implementation of A may conditionally incorporate the implementation of B in order to
accomplish its objective if a use case B extends a different use case A. That is, in some
circumstances, A might finish the job without B. But A might need B based on the condition that
was mentioned. In this instance, B is reliant on A and is unable to exist independently. B cannot
extend more than one use case because of this. The execution phase at which A's use case narrative
depends on B is referred to as an extension point.

18
Diagram:

19
20
21
22
23
24
25
26
27
28
29
2. Class Diagram:
A class diagram is a specific kind of diagram and a component of the unified modeling language
(UML), which specifies and presents the overview and structure of a system in terms of classes,
characteristics, and methods, as well as the connections between various classes. It is used as a system
development resource throughout the software development life cycle to illustrate and generate a
functional diagram of the system classes
Notations:
Classes: An abstraction of entities with similar traits is
represented by classes. The connections between
classes are represented by associations

Active Classes: While passive classes merely store data and provide
services to other classes, active classes start the action and manage its
flow. Classes that are active should have a thicker border

Visibility: To indicate who has access to the information in a class, use visibility markers. Information that
is private visibility, indicated by a minus sign, is hidden from anyone outside the class partition. The
marked information is visible to all other classes when it is marked with the plus sign (public visibility).
Child classes can access data they inherited from a parent class thanks to protected visibility, which is
indicated by a # symbol

Associations: Associations show the fixed connections between classes. Put association names on the
association line, above it, or below it. To show the relationship's direction, use a full arrow. Place the roles
at the association's conclusion. Roles illustrate how the two classes view one another

30
Multiplicity (Cardinality): Put multiplicity notations close to an association's ends. These symbols show
how many instances of one class are connected to one instance of another. As an illustration, one company
might employ one or more people, but they all work for the same business

Constraint: Place constraints inside curly braces {}

Composition and Aggregation: A unique kind of aggregation called composition indicates a strong
ownership relationship between Class A, the whole, and Class B, its component. Give an example of
composition using a filled diamond. Use a hollow diamond to symbolize an easy aggregation relationship
where the "whole" class is more significant than the "part" class but there is no dependency between the
two classes. The diamond's final relationships in terms of composition and aggregation point to the
"whole" class (i.e., the aggregation)

31
32
Generalization: Generalization is another term for inheritance or a relationship where "is a" is present.
When one class is a specialized variation of another, it alludes to the relationship between the two classes.
For instance, a type of car is a Honda. As a result, there would be a generalization between the class
Honda and the class automobile

Explain: For clarity, I've divided the class diagram shown above into three sections. The menu portion
comes first. To give classes that implement it access to its ShowMenu() and SelectMenu() functions, I
employ an interface called IMenu in the menu section. EmployeeMenu (used to call features of the
Employee class), CustomerMenu (used to call features of the Customer class), ProductMenu (used to call
features of the Product class), and MainMenu (used to call features of the MainMenu class) are the classes

33
that implement the IMenu interface (used to jump to the Menu classes mentioned above). Second, I then
build a Person class, followed by Employee and Customer classes, all of which inherit from the Person
class (inherited properties include id (type string), name (type string)) , address (type string) and phone
(string type).In the Product class there are 3 properties: id(type string), name(type string), price(type
string). Finally, in the Product class, there are 6 functions including AddProduct(), UpadateProduct(),
DeleteProduct(), FindProduct(), ViewAllProduct(), BackToMenu(). In Customer class, there are 6
functions including AddCustomer(), UpadateCustomer(), DeleteCustomer(), FindCustomer(), ViewAll(),
BackToMenu(). At Employee class, there are 6 functions including AddEmployee(), UpadateEmployee(),
DeleteEmployee(), FindEmployee(), ViewAll(), BackToMenu().

34
REFERENCES
[1] GeeksforGeeks. 2022. C# | Abstract Classes - GeeksforGeeks. [ONLINE] Available at:
https://www.geeksforgeeks.org/c-sharp-abstract-classes/. [Accessed 05 December 2022].
[2] Educative: Interactive Courses for Software Developers. 2022. What is objectoriented programming?
OOP explained in depth. [ONLINE] Available at: https://www.educative.io/blog/object-oriented
programming. [[Accessed 05 December 2022].
[3] GeeksforGeeks. 2022. C# | Constructors - GeeksforGeeks. [ONLINE] Available at:
https://www.geeksforgeeks.org/c-sharp-constructors/?ref=lbp. [[Accessed 05 December 2022].
[4] GeeksforGeeks. 2022. C# | Inheritance - GeeksforGeeks. [ONLINE] Available at:
https://www.geeksforgeeks.org/c-sharp-inheritance/?ref=lbp. [Accessed 05 December 2022].
[5] GeeksforGeeks. 2022. C# | Encapsulation - GeeksforGeeks. [ONLINE] Available at:
https://www.geeksforgeeks.org/c-sharp-encapsulation/?ref=lbp. [Accessed 05 December 2022].
[6] GeeksforGeeks. 2022. C# | Abstraction - GeeksforGeeks. [ONLINE] Available at:
https://www.geeksforgeeks.org/c-sharp-abstraction/?ref=lbp. [Accessed 05 December 2022].
[7] WhatIs.com. 2022. What is polymorphism? - Definition from WhatIs.com. [ONLINE] Available at:
https://www.techtarget.com/whatis/definition/polymorphism#:~:text=In%20 object%2Doriented
%20programming%2C%20polymorphism,have%20more%20than%20one%20form.. [Accessed 05
December 2022].
[8] Educative: Interactive Courses for Software Developers. 2022. What is polymorphism? [ONLINE]
Available at: https://www.educative.io/answers/what is-polymorphism. [Accessed 05 December 2022].
[9] Lucidchart. 2022. UML Class Diagram Tutorial | Lucidchart. [ONLINE] Available at:
https://www.lucidchart.com/pages/uml-class-diagram. [Accessed 05 December 2022].
[10] Viblo. 2022. Design Pattern: Class Diagram. [ONLINE] Available at: https://viblo.asia/p/design-pattern-
class-diagram-L4x5xGVYlBM. [Accessed 05 December 2022].

35

You might also like