Unit 20 - Assignment 1 Frontsheet
Unit 20 - Assignment 1 Frontsheet
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:
In this report, I will clarify the concepts of object-oriented programming and design patterns, attributes and characteristics of each.
Besides, I will also mention the specific assumed scenarios applied in each feature, along with the diagrams that help to
generalize the protocols of each object. Finally, I will analyze the relationship between object-oriented programming and
design pattern.
According to (Alexander Petkov, 2018), I have conducted to research that object-oriented programming is considered a model of a
programming language, in which objects and data are more focused instead of logic or functions. An object in OOP is considered
a data field that includes unique attributes and behaviors. The first thing when implementing OOP is that we need to identify all
the objects we want to work with and how they relate to each other. This step is often called the "data modeling" step. Next, once
we have identified a specific object, we need to determine the type of data it contains and any logical sequence of commands that
can be executed with it. We can call a separate logic sequence as a method and objects can communicate with well-defined
interfaces called messages. There are four principles of object-oriented programming are (Alexander Petkov, 2018) :
Encapsulation
This principle helps the actions or states of objects to be kept private within a defined boundary or class.Other objects will not
have direct access to these states, instead, they can only communicate with the object through the methods provided. This feature
provides data security for large programs and avoids corruption of data from outside
Abstraction
This principle is considered a natural extension of the principle of packaging. It eases the pressure of maintaining a large code
base when objects have to communicate a lot (especially large objects). In other words, this mechanism will hide internal
implementation details, which makes it easier for developers to make changes and additions over time.
Inheritance
In OOP, objects will often be very similar, sharing common logic, but not quite the same.Therefore, this principle helps us to
reuse common logic and extract it into a separate class. This means that the programmer will create a class (child) and
derive from another (parent) class and they will have a hierarchy.This attribute of OOP forces programmers to analyze
data more thoroughly and ensure a higher level of accuracy
Polymorphism
This principle provides a way to re-use the same classes as the parent class without having to confuse the mix types. In other
words, the objects are allowed to perform more than one form, then the program will determine which uses are needed for each
execution, to reduce the need to copy the code.
Basically, OOP operates in a form that focuses on objects rather than necessary logic rules. This operation is very
suitable for large programs with many different entities and is constantly updated. In addition, OOP has several other benefits
such as code re-use, scalability and efficiency. However, OOP has also been criticized for many reasons, one of the biggest
reasons is that overemphasizes the data component of software development and does not focus enough on computation or
algorithmsIn. In addition, OOP will be more complicated to design and more time-consuming to compile
We want to use the university library system as an example for OOP. This system contains 3 actors: borrower, librarian
and admin. The borrower has abilities to login, search books, borrow books, order books, return books and pay fine if
borrow books overdue. The librarian has abilities to login, search books,insert data, check for browed book and statistic
borrowers. The admin has abilities to login, search for all users’ information and manage them.
2. Usecase diagram
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
Use case 1: Management system
Use case 2: User system
Use case 3: Librarian system
The diagram above includes three main entities: borrowers, librarians and admin. Admin will be responsible for managing the entire
system and managing all accounts. He also has the right to check account information of librarian if necessary. Librarians and
borrowers who want to use the library will have to have an account, log into the system to be able to search for books
3. Class Diagram
IV. Determine a design pattern and define class diagrams using a UML tool for each of the creational, structural, and
behavioral pattern types
1. Design Patterns
- 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.
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".
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.
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. Structure class patterns use inheritance to edit interfaces or settings. 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.
Definition: is a design pattern that allows adding behavior to an individual object, without affecting the behavior of other objects
in the same class. This type of design has a structure that acts as a wrap for the existing layer. Whenever a new feature is needed,
the existing object is wrapped in a new object (decorator class).
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.
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.
Definition: The strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting
an algorithm at runtime. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a
family of algorithms to use. Strategy lets the algorithm vary independently from clients that use it. Deferring the decision about
which algorithm to use until runtime allows the calling code to be more flexible and reusable
Scenario: I will use the program to sum and difference of two integers to illustrate the Strategy Pattern structure.
V. Conclusion
The above report summarizes the content of object-oriented programming and design patternsincluding definitions, characteristics
and classification. In addition, the report also includes a number of assumed scenarios and UML diagrams so readers can easily
visualize the usage and importance of each feature of OOP and design patterns.
VI. References
Erich Gamma et al, 1994. Design Patterns, Elements of Resuable Object-Oriented Software. 1st ed. Canada: Addison-Wesley