Professional Documents
Culture Documents
1651 - Võ Bì Thành Phư C - GCS200547 - Assignment 1
1651 - Võ Bì Thành Phư C - GCS200547 - Assignment 1
Advanced Programming
ASSIGNMENT
No.1
Class: GCS0903B
Assignment title Examine and design solutions with OOP and Design Patterns
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
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
Page 2
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.
LO1 Examine the key components related to the object-orientated programming paradigm,
analysing design pattern types
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
UML tool. given code scenario using a
UML tool.
Page 3
Table of Contents
P1. Examine the characteristics of the object-orientated paradigm as well as the various class
relationships. .................................................................................................................................... 5
3. Encapsulation ....................................................................................................................... 6
6. Interface ............................................................................................................................... 9
1. Scenario .......................................................................................................................... 11
[M1 & M2] Determine a design pattern and define class diagrams using a UML tool for each of
the creational, structural, and behavioral pattern types ............................................................... 20
4. Behavior Pattern..................................................................................................................... 24
References...................................................................................................................................... 27
Page 4
P1. Examine the characteristics of the object-orientated paradigm
as well as the various class relationships.
1. Object-oriented programming
Object-oriented programming (OOP) is one of the very important programming
techniques nowadays. It is applicable in most practical construction applications at
businesses. Most popular programming languages and programming frameworks such
as Java, C#, and .NET support object-oriented programming. Most programmers have
learned about object-oriented programming in universities, but the basic principles of
object-oriented programming sometimes do not know how to misuse the wrong
philosophy of programming. object-oriented.
In this article, I will summarize the basic principles of object-oriented programming
to help you get an overview of OOP and how convenient it is.
What is object-oriented programming?
Object-oriented programming is a programming technique that allows
programmers to create objects in code that abstract actual objects in life. This approach
is currently very successful and has become one of the software development
templates, especially for software using on business.
When developing applications using OOP, we will define classes (classes) to model actual
objects. In the application these classes will be initialized into objects and during the
time the application runs, the methods of this object will be called.
What is the class that defines the object: include methods and properties. An
object is just an instance of the class. Classes interact with each other by the public API:
its set of methods, its public properties.
Page 5
content, the recipient information, the result of sending the message successfully or
failure. That is abstraction.
❖ Advantages of using abstraction for programming:
− Abstraction allows programmers to eliminate the complexity of an object by only
giving the object's needed attributes and methods in programming, improving
the maintainability of the system.
− Abstraction helps us focus on the essential core of the object rather than being
concerned with how it works.
− Abstraction provides many extended features when used in combination with
polymorphism and inheritance in object-oriented programming.
− Java abstracts through abstract classes and interfaces. In this article, I will guide
you to learn about abstract classes and abstract methods
3. Encapsulation
❖ Definition
- This property does not allow the user to change the intrinsic state of an
object. Only the object's internal methods allow to change its state. In any
way, allowing the external environment to affect the internal data of an
object is entirely up to the person writing the code. This is a property that
ensures the integrity of the object. Encapsulation enables a group of
properties, methods, and other members to be considered a single unit or
object.
❖ Example
❖ Implementation
- Public: Access to all code in the program
- Private: Access to only members of the same class
Page 6
- Protected: Access to members of same class and its derived classes
- Internal: Access to current assembly
❖ Purpose
- The purpose of inheritance is to reuse common methods and attributes among
classes without recreating them. Reusability of a code enables you to use the
same code in different applications with little or no changes.
❖ Example
- I am presenting an example that is quite familiar to movies viewer. You know in
the “Lion King”, Simba is Mufasa son and in “Lion King 2”, Kiara is Simba daughter,
meaning Simba inherits from Mufasa and Kiara inherits from both Simba and
Mufasa:
Page 7
➢ Protected Access Modifier:
- The protected access modifier protects the data members that are declared
using this modifier.
- The protected access modifier is specified using the protected keyword.
- Variables or methods that are declared as protected are accessed only by the
class in which they are declared or by a class that is derived from this class.
- The following figure displays an example of using the protected access modifier:
Page 8
➢ New keyword:
- The new keyword can either be used as an operator or as a modifier in C#. This
allows you to redefine the inherited methods or variables in the derived class.
Since redefining the base class members in the derived class results in base class
members being hidden, the only way you can access these is by using the base
keyword.
-
5. Concept of polymorphism
Polymorphic techniques in object-oriented programming languages enable
programmers to increase the ability to reuse code written in a general way and can
change behavior flexibly. depending on the type of object.
Polymorphism in Java is understood in each case, different circumstances, the
object has different morphology depending on the context. The polymorphic object is a
special object because sometimes it becomes another object and sometimes it becomes
another object (depending on the situation). This "role-playing" in different objects
makes it possible for the original polymorphic object to perform different actions of
each specific object.
6. Interface
❖ Features of Interface
− The interface has only abstract methods.
− Interface is a technique to achieve complete abstraction and multiple inheritance
in C#.
− The interface always has a modifier: public interface, whether you explicitly
specify it or not.
− If there are fields, they are: public static final, whether you specify them.
− Its methods are abstract methods, meaning there is no function body, and all
modifiers are: public abstract, whether you declare it or not.
Page 9
− Interface has no constructor.
− An interface is not a class. Writing an interface is like writing a class, but they
have two different definitions. A class describes the properties and behavior of
an object. An interface contains the behaviors a class implements.
− Unless an interface implementation class is an abstract class, all of the interface's
methods need to be defined in the class.
− The IDE adds the keyword public abstract before the interface method and public
static final keywords before data members.
− An interface is written in a file in .java format, with the interface name the same
as the file name.
− The interface's Bytecode is saved in a .class file format.
− Declaring interfaces in a package, the corresponding bytecode files also have a
directory structure with the same package name.
Page 10
P2. Design and build class diagrams using a UML tool
1. Scenario
Based on the scenario, we are developing a Student Management System for FPT
Academy International. The system requirement the information below:
Page 11
Page 12
2. Use-case Diagrams:
To present a brief look at what the system can do, we need to draw out a use-case
diagram - a diagram showing how users in the system can interact with the system via
the features. Thus, and according to the above information, we can have the following
use-case diagrams
Page 13
Use-case 1: Management System
− In the above diagram, you can see that User (or Admin) can access 3 main
options,
− “Managing Student”, “Managing Lecturer” and “Exit”
− Choosing “Managing Student”, system will display a Menu allowing user to
manage the students via the functionalities (Add, Search, View, Delete, Update)
Choosing “Managing Lecturer”, system will display a Menu allowing user to
manage the lecturers via the functionalities (Add, Search, View, Delete, Update)
− Choosing “Exit”, system will end.
− We can briefly imagine how the system would work through the above diagram,
now we will take a closer look on how we can manage the students and the
lecturers.
Page 14
Use-case 2: Student Manage System
− As you can see, the user will manage the students and lecturers through the
functions: Add new Student, View all the Student, Search the Student, Update
Student, Delete the Student and Return to Main Menu.
− In case, we want to stop adjust and examine the target or want to change to the
other Managing side.
Page 15
Use-case 3: Lecturer Manage System
− As you can see, the user will manage the students and lecturers through the
functions: Add new Lecturer, View all the Lecturer, Search the Lecturer, Update
Lecturer, Delete the Lecturer and Return to Main Menu.
− In case, we want to stop adjust and examine the target or want to change to the
other Managing side.
Page 16
3. Class Diagrams:
− After knowing the actual functios that will be used to manage the targets, we
now need to determine the classes, the interfaces and their relationship that
will be used in the system. And to determine those, I drew the following Class
Diagram - one of the most important diagrams of software design, it shows
the structure and relationship between the components that make up the
software.
− As you can see in the diagram, there are 6 classes (Main Menu, Student
Menu, Lecturer Menu, Student, Lecturer, Person) and one interface
(Function) that will be used in the system and their relationships are also
clearly defined.
Page 17
Name Type Description Relationship
Page 18
Including the properties from Generalization relationship:
“Person” and other inherit from “Person”.
Lecturer Class properties: Id and Name with Dependency
the conditions in the scenario, Relationships: with
Lecturer List for data storage “Lecturer Menu”
Association
Relationships:
Including the functionalities in
Student With “Main Menu”.
Class the “function” as well as the
Menu Dependency
data in the “Student”
Relationships: with
“Student”
Association
Relationships:
Including the functionalities in
Lecturer With “0Main Menu”.
Class the “function” as well as the
Menu Dependency
data in the “Lecturer”
Relationships: with
“Lecturer”
Page 19
[M1 & M2] Determine a design pattern and define class diagrams
using a UML tool for each of the creational, structural, and
behavioral pattern types
1. Design Pattern
- A design pattern is a total solution to common problems in software
design. A design pattern is not a complete design so that it can be directly
converted into code; It is only a model describing how to solve problems that can
be used in many different situations.
- Design Patterns are not specific languages at all. It can be implemented in
most programming languages, such as Java, C #, even Javascript or any other
programming language.
- Design patterns can help make our designs more flexible, easy to change
and maintain.
2. Creational Pattern
- Creational Pattern are designs pattern that deal with object creation
mechanisms, trying to create objects in a way that fits the situation. The basic
form of creating objects can lead to design problems or add design complexity.
The creative design solves this problem in some way controlling the creation of
this object.
- Try to create objects in a way that fits the situation: Instead of "new
someClass ()", use "template.Create ()"
- Creative designs include two key ideas. One is to encapsulate knowledge
about the specific classes the system uses. Another way is to hide the way the
instances of these specific classes are created and combined.
- Have five type of Creational Pattern: Abstract Factory Pattern, Builder
Pattern, Factory Method Pattern, Prototype Pattern and Singleton Pattern.
Page 20
- I will use Abstract Factory Pattern to give an example:
Creational Pattern
2.1. Definition:
- Abstract Factory Pattern is an object-oriented pattern design in computer
software design, providing a class interface that creates a set of related or
interdependent objects without specifying them as specific classes.
- Abstract Factory design pattern encapsulates a group of classes that play
a "production" role
in the application, which are the classes used to create objects. These production classes
share a programming interface inherited from a pure virtual parent class called "virtual
production layer".
2.2. Why use it:
- Initializing Objects that hides the logical handling of creation. o It
alleviates the exchange of objects families. o It promotes consistency
between objects.
2.3. Scenario:
- I use a smartphone's information description program to illustrate
the structure of Abstract Factory Pattern.
- The example here is implementing an Abstract Factory in the form
of the IMobilePhone Interface, which has methods that can create
Smartphone object and Normal Phone objects. The client code against
IMobilePhone and gets ISmartPhone and INormalPhone interfaces.
Page 21
- In the case of "Nokia", it creates a family of Nokia objects
(SmartPhone and NormalPhone) and in the "Samsung" case, creates a
family of Samsung objects (SmartPhone and NormalPhone). o
IMobilePhone interface returns as it codes against ISmartPhone and
INormalPhone interface.
-
2.4. Class Diagram:
Class Diagram
Page 22
3. Structural Pattern
- Structure designs are designs that make it easy to design by simply identifying a
relationship between entities.
- Structure patterns describe ways to assemble objects to perform a new function
o Identify how different classes and objects are combined to form larger structures. o
Structure class patterns use inheritance to edit interfaces or settings. o The structured
object templates compose objects for new functions.
- Have 6 popular type of Structural Pattern: Adapter Pattern, , Bridge Pattern,
Composite Pattern, Decorator Pattern, Façade Pattern, Flyweight Pattern.
Structural Pattern
Page 23
3.3 Scenario:
In this program I will illustrate the process of enchanting an item in a game such
as Sword and Iron armor, the program will return the name and value of the item.
3.4 Class Diagram:
Class Diagram
4. Behavior Pattern
- Behavioral design patterns are designs that identify common communication
patterns between objects and identify patterns. By doing so, these patterns increase
the flexibility in making this communication.
- Behavioral patterns are concerned with communication (interaction) between
the objects, either with the assignment of responsibilities between objects.Or
encapsulating behavior in an object and delegating requests to it.
- Have 10 popular type of Behavior Pattern: Chain of responsibility Pattern,
Command Pattern, Iterator Patter, Mediator Pattern,Memento Pattern, Observer
Pattern, State Pattern, Strategy Pattern , Template Method Pattern and Visitor
Pattern.
Page 24
Behavioral Pattern
Page 25
4.4. Class Diagram:
Class Diagram
Page 26
References
Page 27
[10] Viblo. 2022. Design Pattern: Class Diagram. [ONLINE] Available
at: https://viblo.asia/p/design-pattern-class-diagram-L4x5xGVYlBM. [Accessed 20
August 2022].
[11] What's a design pattern?. 2022. What's a design pattern?. [ONLINE]
Available at: https://refactoring.guru/design-patterns/what-is-pattern. [Accessed
20 August 2022].
[12] Design Pattern Quick Guide. 2022. Design Pattern Quick Guide. [ONLINE]
Available
at: https://www.tutorialspoint.com/design_pattern/design_pattern_quick_guide
.htm. [Accessed 20 August 2022].
[13] Creational Design Patterns. 2022. Creational Design Patterns. [ONLINE]
Available at: https://refactoring.guru/design-patterns/creational-patterns.
[Accessed 20 August 2022].
[14] Structural Design Patterns. 2022. Structural Design Patterns. [ONLINE]
Available at: https://refactoring.guru/design-patterns/structural-patterns.
[Accessed 20 August 2022].
[15] Behavioral Design Patterns. 2022. Behavioral Design Patterns. [ONLINE]
Available at: https://refactoring.guru/design-patterns/behavioral-patterns.
[Accessed 20 August 2022].
[16] Abstract Factory. 2022. Abstract Factory. [ONLINE] Available
at: https://refactoring.guru/design-patterns/abstract-factory. [Accessed 20
August 2022].
[17] Decorator. 2022. Decorator. [ONLINE] Available
at: https://refactoring.guru/design-patterns/decorator. [Accessed 20 August
2022].
[18] Strategy. 2022. Strategy. [ONLINE] Available
at: https://refactoring.guru/design-patterns/strategy. [Accessed 20 August
2022].
Page 28