Professional Documents
Culture Documents
Vuong Khay Thanh FGW HN 396693 0 1
Vuong Khay Thanh FGW HN 396693 0 1
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
P1 P2 M1 M2 D1 D2
Summative Feedback: Resubmission Feedback:
2.1
Table of Figure
Figure 1-Data Abstraction ........................................................................................................................................................................................... 9
Figure 2-Example code of Data Abstraction ............................................................................................................................................................. 10
Figure 3 Encapsulation ................................................................................................................................................................................................. 11
Figure 4 Inheritance ..................................................................................................................................................................................................... 13
Figure 5 Polymorphism ................................................................................................................................................................................................ 14
Figure 6 user case ........................................................................................................................................................................................................ 16
Figure 7 Class diagram ................................................................................................................................................................................................. 20
Figure 8 Builder Design Pattern ................................................................................................................................................................................... 29
Figure 9 Strategy Design Pattern ................................................................................................................................................................................. 31
Figure 10 Adapter Design Pattern................................................................................................................................................................................ 33
List of Table
Table 1-Difference between class and object ............................................................................................................................................................. 8
Table 2 Select the character ........................................................................................................................................................................................ 17
Table 3 Select play mode ............................................................................................................................................................................................. 18
Table 4 Choose the types of billiard game ................................................................................................................................................................... 18
Table 5 Choose action in the game .............................................................................................................................................................................. 19
I. Introduction
Programming language features that are considered advanced are used for efficient software development, which can affect
the performance of the application as well as the readability and scalability of the code. Many of the commercial applications
available today, whether for work or play, will use one or more design patterns in their development. A design pattern is a
description of how to solve a problem that can be used in a variety of situations and can help deepen understanding of object-
oriented programming and help improve design and reusability. software. In this report, we will talk about OOP and design
patterns, so that readers can understand how to create effective applications, improve application performance. the goals of
the report to Understand about 4 characteristics of OOP includes: Abstraction, Encapsulation, Polymorphism and Inheritance,
Understand about OOP and Design Pattern, Understand relationship between OOP and Design Pattern.
A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of
instruction to build a specific type of object. It provides initial values for member variables and member functions or methods. (Martin,
2021)
3. Encapsulation
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the
data it manipulates. In Encapsulation, the variables or data of a class are hidden from any other class and can be accessed only
through any member function of their class in which they are declared. As in encapsulation, the data in a class is hidden from
other classes, so it is also known as data-hiding. (sambhav228, 2020)
All we need to understand is the interface that is provided for us. While abstraction addresses the characteristics of an object
from an external viewer's perspective, encapsulation focuses on the implementation of an object. Besides, the implementation
encapsulates the details about an abstraction into separate elements. The implementation should be considered a secret of the
abstraction and hidden from most clients.
Figure 3 Encapsulation
4. Inheritance
Inheritance is an important pillar of OOP (Object-Oriented Programming). The capability of a class to derive properties and
characteristics from another class is called Inheritance. When we write a class, we inherit properties from other classes. So,
when we create a class, we do not need to write all the properties and functions again and again, as these can be inherited
from another class that possesses it. Inheritance allows the user to reuse the code whenever possible and reduce its
redundancy. (sambhav228, 2020)
In c# inheritance, the class whose members are inherited is called a base (parent) class and the class that inherits the members
of base (parent) class is called a derived (child) class.
Multi-Level Inheritance
Generally, c# supports only single inheritance that means a class can only inherit from one base class. However, in c# the
inheritance is transitive and it allows you to define a hierarchical inheritance for a set of types and it is called a multi-level
inheritance.
For example, suppose if class C is derived from class B, and class B is derived from class A, then the class C inherits the
members declared in both class B and class A.
Multiple Inheritance
As discussed, c# supports only single inheritance that means a class can only inherit from one base class. In case, if we try
to inherit a class from multiple base classes, then we will get a compile time error.
Figure 4 Inheritance
5. Polymorphism
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be
displayed in more than one form. For example, A person at the same time can have different characteristics. Like a man at the same time is
a father, a husband, an employee. So, the same person possesses different behavior in different situations. This is called polymorphism.
(sambhav228, 2020)
• Overloading: occurs when two or more methods in one class have the same method name but different parameters.
• Overriding: occurs when two methods have the same method name and parameters.
Figure 5 Polymorphism
III. Scenario
There is a billiards tournaments that gather a lot of players, snooker has 2 types, Carom, Carom billiards, also known as Phang
billiards. In this game, you must hit the cue ball on both object balls and hit the boundary at least once before the second target
ball hits. If this happens, you get a point. When no marbles are hit, one point is deducted. The first player to reach the agreed
number of points is the winner. and Billiard to win you must be the first to hit 5 or 8 balls into the pocket. billiard balls will
also have different color features, billiards tables are also divided into many types. billiards has a billiard triangle used to
rearrange the billiards table. In billiards.
• Ball: The ball is an object that the player will interact with to be able to play this sport. Ball includes: color, number of
balls, ball size.
• Table: The table is where players can play billiards on top of it. Depending on the needs of the user, there will be
mainly 3 sizes of tables for 3 different billiards. The pool table consists of 6 holes, with a barrier, usually green. billiard
carom table only includes barrier tape, no ball holes. billiard snooker consists of 6 holes and barrier, same as pool table
but larger size.
• billiard sticks: is what the user will use to be able to hit the cue ball into the target marbles to get points depending on
the rules of the game. Billiard bats can vary in size and weight depending on the purpose, such as pool players will use
medium and medium length clubs, breaking marbles will use short and heavy clubs with large heads....
• Character: As someone who will play billiards, each person will have their own characteristics such as the skill level of
each separate billiard discipline, gender, hometown, ....
• Billiards Skills: is the player's technique to be able to control the cue ball at his discretion. It includes techniques such
as cule, masse, tonic.
Players enter the game, choose a table, choose a game mode, choose a stick to play, when playing, they will use a stick to hit,
depending on the player's hitting power, the ball will fly far or near.
Figure 6 user case
Table 2 Select the character
Description: Players can choose from one of the available sample characters,
including their name, age, nationality, and gender.
Actors: user
Preconditions: 1. no
Postconditions: After choosing a character, there will be a pop-up window asking the
player to agree to choose the character or decline. If the player chooses
yes, they will be taken to the game's menu screen, if not, they will be
taken back to the character selection screen.
Flow: 1. open game
1. Click on character selection
1. Select the desired character
1. press the agree button
1. complete character selection
1. Takes to the game menu screen
Exceptions: no
Table 3 Select play mode
Postconditions: no
Flow: 1. open game
1. Click on game mode
1. Select game mode
1. press the agree button
1. complete game mode selection
Exceptions: no
Description: Players can choose 1 of 3 types of billiards to play, that is pool, snooker,
carom
Actors: user
Preconditions: after selecting the game mode
Postconditions: no
Flow: 1. Click on continue button after selecting the game mode
1. Select type of game
1. press the agree button
1. complete choose type of game
Exceptions: no
Description: After entering the game, the player can choose the actions of the
character to be able to interact with the game, such as choosing a stick,
choosing a target ball, choosing a shot force.
Actors: Librarian
Preconditions:
after choose type of game
Postconditions: no
Flow: 1. Click on continue button after choose type of game
1. Choose stick
1. Choose target ball
1. Choose shot force
1. complete
Exceptions: no
Figure 7 Class diagram
• The table will have the size and color on the tabletop, the table has two styles, Carom and Billiard Pool, depending on
the size of the table. The Pool Pool table has an additional 6 holes.
• in billiards with balls, depending on the type of game, there will be different sizes and colors, especially CaromBall has
an additional number of each ball.
• Players, in addition to hitting the ball, each player will use a stick, depending on the type of stick will have different
hitting power.
• Adapter: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that
couldn't otherwise because of incompatible interfaces.
• Bridge: Decouple an abstraction from its implementation so that the two can vary independently.
• Composite: Decouple an abstraction from its implementation so that the two can vary independently.
• Decorator: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub
classing for extending functionality.
• Facade: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that
makes thesubsystem easier to use
Adapter Pattern
An Adapter Pattern says that just "converts the interface of a class into another interface that a client wants". In other words,
to provide the interface according to client requirement while using the services of a class with a different interface. The
Adapter Pattern is also known as Wrapper.
Usage of Adapter Pattern
• When an object needs to utilize an existing class with an incompatible interface.
• When you want to create a reusable class that cooperates with classes which don't have compatible interfaces.
• When you want to create a reusable class that cooperates with classes which don't have compatible interfaces.
3. Behavior Pattern
Behavioral design patterns are design patterns that identify common communication patterns between objects and realize
these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
Algorithms and the assignment of responsibility amongst objects are the focus of behavioral patterns. Not only do behavioral
patterns represent patterns of objects or classes, but they also explain patterns of communication between them. Complex
control flow that is difficult to follow at run-time is characterized by these characteristics. They divert your attention away
from the flow of control, allowing you to focus just on the interconnections between items. By doing so, these patterns increase
flexibility in carrying out this communication.
List of behavioral patterns
• Chain of responsibility: A behavioral design pattern that lets you pass requests along a chain of handlers. Upon
receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.
• Iterator: A behavioral design pattern that lets you traverse elements of a collection without exposing its underlying
representation
• Command: A behavioral design pattern that turns a request into a stand-alone object that contains all information
about the request. This transformation lets you pass requests as a method argument, delay or queue a request’s
execution, and support undoable operations
• Template Method: A behavioral design pattern that defines the skeleton of an algorithm in the superclass but let
subclasses override specific steps of the algorithm without changing its structure.
• Strategy: A behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class,
and make their objects interchangeable.
• Observer: A behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about
any events that happen to the object they’re observing.
• Mediator: A behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts
direct communications between the objects and forces them to collaborate only via a mediator object
Chain Of Responsibility Pattern
In chain of responsibility, sender sends a request to a chain of objects. The request can be handled by any object in the chain. A
Chain of Responsibility Pattern says that just "avoid coupling the sender of a request to its receiver by giving multiple objects a
chance to handle the request".
Usage of Chain Of Responsibility
• When more than one object can handle a request and the handler is unknown.
• When the group of objects that can handle the request must be specified in dynamic way
V. Scenario Design Patterns
1.1 Builder Design Pattern for scenario (Creational Design Patterns )
Program for a car manufacturing company , a car is a complicated object that can be built in a variety of ways. We
separated the car assembly code into a separate car builder class rather than bloating the Car class with a large
constructor. A set of methods for configuring various parts of a car are available in this class.
•
This Builder pattern illustrates how you can reuse the same object construction code when building different types of
products, such as cars, and create the corresponding manuals for them.
Builder (ICarBuilder)
Is an abstract class or interface that declares a method to create a car object.
ConcreteBuilder (CarBuilder)
Inherit the Builder and install the details of how to create cars.
Director
Build the car using ICarBuilder, which calls the Builder to create the object.
Product (Car)
represents the car object to be created, this object is complex, has many properties.
1.2 Strategy Design Pattern for scenario (Behavioral Design Patterns)
The company's competitive strategy is to create many discount times such as percentage discounts, free on certain types of
items on special occasions. The company believes that offering many discount opportunities can attract more customers for
the company.
There are 3 basic promotions:
• Free: The price of the product is 0 VND.
• Promotion based on discount percentage: Buyer selects the appropriate percentage to set the discount, which
must be greater than ten percent.
• Promotion by quantity: Customers who buy n products will get x discount
Mission is to create a system to solve this problem.
Now that you have studied English outside, you have got an ielts degree. the school has not implemented a program to
exchange points or recognize ielts scores. Up we wrote this program for the purpose of helping to convert ielts points to PTE.
This will help you save time and be able to graduate on time.
Figure 10 Adapter Design Pattern
Explanation:
• PTE: table containing information about the issue date day expires and the test scores of detech students. PTE score is
an integer (int) between 0-90)
• IELTS: table contains information about date date expires and the test scores of external students study. This point
number (double) ranges from 0.0-9.0
• StudentGreenwich: Inherit the Student class and students at Greenwich will be awarded a PTE
• StudentCenter: Students who study English at IELTS centers are awarded Ielts degrees.
• Student: contains student information
• StudentAdapter: Because FPT only accepts PTE degrees to “StudentAdapter” with the goal of helping to convert IELTS
scores to PTE scores so that students at the Center do not have to retake or re study to get a PTE degree.
VI. Design Pattern vs OOP
Object Oriented programming is a programming paradigm fundamental to many programming languages. If you follow this
paradigm you use objects to approach the overall program. The objects contain data and behaviors and you connect them in
logical ways to successfully solve the task at hand.
Beside, design pattern is a tried and tested solution to a common programming pattern. It could be considered a best practice.
This solution is robust, scalable, readable and flexible. If you approach a program using an Object-Oriented paradigm, there are
a number of design patterns you can then draw on to solve specific problems.
Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it
as may be the case with a commercial class library or maybe any change would require modifying lots of existing subclasses.
Design patterns offer ways to modify classes in such circumstances
The concept of Design Pattern is closely associated with Object Oriented Programing (OOP). Design patterns solve many of the
problems object-oriented. There are several of these problems and how design patterns solve them:
OOP Problem:
The hard part about object-oriented design is decomposing a system into objects. The task is difficult because many factors
come into play: encapsulation, granularity, dependency, flexibility, performance, evolution, re-usability, and on and on. They
all influence the decomposition, often in conflicting ways. Many objects in a design come from the analysis model. But object-
oriented designs often end up with classes that have no counterparts in the real world. Some of these are low-level classes like
arrays, others are much higher-level.
Design patterns help you identify less-obvious abstractions and the objects that can capture them. For example: Objects that
represent a process or algorithm don't occur in nature, yet they are a crucial part of flexible designs.
The Strategy pattern describes how to implement interchangeable families of algorithms that can change the price of
products in the promotion strategy in scenario 1.2.
OOP Problem:
Objects can vary tremendously in size and number. They can represent everything down to the hardware or all the way up to
entire applications. How do we decide what should be an object in scenario 1.1 to get a complete car that can run if using OOP
alone it would be very difficult to figure out what the car needs and the configuration of the car like.
Templates allow you to create different styles and representations of an object using the same construction code. from there
we make car parts easily without confusion.
VII. Conclusion
Above is our explanation of object-oriented programming, with object-oriented programming features used specifically in the
Tech Store Class Diagram example. We recognize the importance of object-oriented programming (OOP). OOP allows us to
improve productivity while simplifying the complexity of software development and system maintenance. However, this is
only one aspect of system development To create the most efficient system, we must use other design patterns, which provide
comprehensive answers to frequent difficulties in software design. This activity also presents several types of design patterns
and includes specific examples.
References
Angeliki, K. (2020). tandfonline. Retrieved 3 8, 2022, from https://www.tandfonline.com/doi/full/10.1080/15567036.2020.1831108
2.1 The report covers all sections required in this assignment. OOP general concept has some good details. APIE in OOP is discussed with examples to illustrate
concepts.
OOP scenario is clearly written with Usecase Diagram. Use cases are provided adequately. Class diagram is good and captures all details in scenario.
All 03 categories of Design Patterns: Creational, Structural and Behavioural are included in the report together with class diagrams.