Unit 20 Assignment 1
Unit 20 Assignment 1
Submission date 07 May 2022 Date Received 1st submission 07 May 2022
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.
Student’s signature
Grading grid
P1 P2 M1 M2 D1 D2
Summative Feedback: Resubmission Feedback:
Table of Figures
Figure 1 - Use case diagram ........................................................................................................................................................................ 6
Figure 2 - Public access modifier example ............................................................................................................................................................... 7
Figure 3 - Private access modifier example ............................................................................................................................................................. 7
Figure 4 - Protected access modifier example ........................................................................................................................................................ 8
Figure 5 - Abstract function example 1 .................................................................................................................................................................... 8
Figure 6 - Abstract function example 2 .................................................................................................................................................................... 9
Figure 7 - Inheritance class example ........................................................................................................................................................................ 9
Figure 8 - Polymorphism example 1 ....................................................................................................................................................................... 10
Figure 9 - Polymorphism example 2 ....................................................................................................................................................................... 10
Figure 10 - Builder UML ............................................................................................................................................................................................ 12
1. Introduction
Nowadays, OOP and Design patterns are becoming a trend in the world of programmers. Object-Oriented Programming is a popular
programming method that appears most in the educational career of any programmer. Design Patterns are solution patterns in
software design, which provide customization and other essential abilities to the program. The concept of Object-Oriented
Programming and Design Patterns are explained in this report.
Benefits of OOP
Disadvantages of OOP
3. OOP scenario
3.1. Scenario
To have a better understanding of OOP general concepts, I will have an example of an employee program. In this scenario, you are a
boss of a toy shop, and with the employee program, you could add full-time employees, part-time employees, or a sale. Another
option is to view all of the current employees.
3.3.1. Encapsulation
Encapsulation is the practice of keeping fields within a class private, then providing access to those fields via public methods.
Encapsulation is a protective barrier that keeps the data and code safe within the class itself. We can then reuse objects like code
components or variables without allowing open access to the data system-wide. (Biniasz, 2021)
There are 3 access modifiers we used in this program. Here are some examples of them:
Private: Private properties can only be accessed within the same class
3.3.2. Abstraction
Abstraction uses simple things to represent complexity. We all know how to turn the TV on, but we don’t need to know how it works
in order to enjoy it. In Java, abstraction means simple things like objects, classes, and variables represent more complex underlying
code and data. This is important because it lets you avoid repeating the same work multiple times. (Biniasz, 2021)
In this example, we can see that there is nothing in the function Salary(). I only declared and left it there.
Figure 6 - Abstract function example 2
3.3.3. Inheritance
Inheritance is A special feature of Object-Oriented Programming in Java; Inheritance lets programmers create new classes that share
some of the attributes of existing classes. Using Inheritance lets us build on previous work without reinventing the wheel. (Biniasz,
2021)
In this example, class Partime is inherited from class Full-time, which will make Partime a sub-class of Fulltime class.
3.3.4. Polymorphism
Polymorphism allows programmers to use the same word in Java to mean different things in different contexts. One form of
polymorphism is method overloading. That’s when the code itself implies different meanings. The other form is method overriding.
That’s when the values of the supplied variables imply different meanings. (Biniasz, 2021)
Figure 8 - Polymorphism example 1
In these examples, there are 2 functions that have the same name, inherited from another class but they override the function from
the owner.
4. Design Patterns
A design pattern is a generic, repeatable solution to general problems that software developers faced during software development.
A design pattern isn't a finished design that can be turned into code right away. It's a description or template for solving an issue
that may be applied to a variety of scenarios. There are 23 different design patterns that can be divided into three groups:
Creational, Structural and Behavioral patterns (TutorialsPoint, 2022).
● Creational Patterns: Instead of instantiating objects directly with the new operator, these design patterns give a mechanism
to construct objects while obscuring the creation logic. This allows the software to decide which items are required for a
specific use case with greater flexibility. The creational pattern includes abstract factory, builder, factory method, prototype,
and singleton.
● Structural Patterns: Class and object composition are the focus of these design patterns. The concept of inheritance is used
to create interfaces and explain how objects can be combined to create new functions. The structural pattern contains an
adapter, bridge, composite, decorator, facade, flyweight, and proxy.
● Behavioral Patterns: These design patterns are focused on object communication in particular. The behavioral pattern
includes the chain of responsibility, command, interpreter, mediator, memento, observer, state, strategy, template method,
and visitor.
A house contains many different aspects such as types of walls, the number of floors, types of roofs, and different backyard settings
such as trees, pool, garden, and more. In the traditional approach, the House constructor will be containing these parameters, which
ends up with a large number of parameters. Additionally, any additional parameter will require further expansion of this hierarchy.
The problem can be addressed through a builder pattern which allows the parameter to be extracted out of its own class and moved
to a builder object.
Figure 10 - Builder UML
The figure above shows an example of a House Builder diagram. There are four classes including Director, Builder interface,
HouseBuilder, ApartmentBuilder and House. A house contains many factors; therefore, it has been extracted into a separate house
builder class instead of a House constructor with a large number of parameters.
The HouseBuilder and ApartmentBuilder classes include a set of methods for assembling various components of a house, such as
floors, roof, and backyard. The director is created for executing the construction steps in a particular order. The result will be sent to
the director through the makeHouse() operation and displayed on the screen.
5.Conclusion
In conclusion, the report has covered the concepts of Design Patterns and Object-Oriented programming, as well as gave detailed
examples of each concept. Such scenarios and diagrams were included in the examples of each conception. In addition, the
comparison of Design patterns and OOP has been analyzed and discussed on the relationship between these two programming
concepts.
6. References
Tyagi, A., 2019. Builder Design Pattern Using C#. [online] C-sharpcorner. Available at: <https://www.c-
sharpcorner.com/article/builder-design-pattern-using-c-sharp/> [Accessed 23 April 2022].
Prasanna, 2022. Advantages And Disadvantages Of OOP | What is OOP?, Objectives of OOP. [online] aplustopper. Available at:
<https://www.aplustopper.com/advantages-and-disadvantages-of-oop/#Disadvantages_Of_Oop> [Accessed 23 April 2022].
BINIASZ, K., 2021. What Are OOP Concepts in Java? How They Work and More. [online] Stackify. Available at:
<https://stackify.com/oops-concepts-in-java/> [Accessed 23 April 2022].