1164-1619624869751-40 - Advanced Programming Reworded 2021 (K.sathurcigan)
1164-1619624869751-40 - Advanced Programming Reworded 2021 (K.sathurcigan)
LO1. Examine the key components related to the object orientated programming paradigm,
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and
grades decisions have been agreed at the assessment board.
Assignment Feedback
Formative Feedback: Assessor to Student
Action Plan
Summative feedback
Assessor Date
signature
1. A Cover page or title page – You should always attach a title page to
your assignment. Use previous page as your cover sheet and make
sure all the details are accurately filled.
2. Attach this brief as the first section of your assignment.
3. All the assignments should be prepared using a word processing software.
4. All the assignments should be printed on A4 sized papers. Use single side printing.
5. Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.
1. The font size should be 12 point, and should be in the style of Time New Roman.
2. Use 1.5 line spacing. Left justify all paragraphs.
3. Ensure that all the headings are consistent in terms of the font size and font style.
4. Use footer function in the word processor to insert Your Name,
Subject, Assignment No, and Page Number on each page. This is
useful if individual sheets become detached for any reason.
5. Use word processing application spell check and grammar check
function to help editing your assignment.
Important Points:
I hereby, declare that I know what plagiarism entails, namely to use another’s
work and to present it as my own without attributing the sources in the correct
form. I further understand what it means to copy another’s work.
Assignment Title
Submission format
The recommended word count is 4,000–4,500 words for the report excluding
annexures. Note that word counts are indicative only and you would not be
penalised for exceeding the word count.
Unit Learning Outcomes:
Learning Outcomes
By the end of this unit students will be able to:
LO1. Examine the key components related to the object-orientated
programming paradigm, analysing design pattern types.
LO2. Design a series of UML class
diagrams.
LO3. Implement code applying design
patterns.
LO4 Investigate scenarios with respect to design patterns.
Assignment Brief and
Guidance:
BOC Software solutions is leading software company in Kandy as system analyst you have
to build an application for Family Dental Care (FDC) considering given scenario.
Family Dental Care (FDC) is a leading up market dental surgery located in Kandy. It
provides all types of dental treatments to patients which include extractions, nerve fillings,
maxillofacial surgeries (i.e. surgeries involving jaw bone) and sophisticated dental implants.
It is visited by prominent dentists and dental consultants with post graduate qualifications,
some of whom are working at the Faculty of Dental Science at the University of Peradeniya.
Patients consult doctors by appointment. On their first visit, patients are required to register
by entering their personal details such as name, address, national identity card number and
contact number. A small fee is charged from the patient during registration. A separate fee
is charged for each treatment given.
Doctors too must get registered at FDC by providing personal details such as name, address,
date of birth, national ID number and contact number. In addition, consultants must provide
the name of their post graduate qualification along with the country of the University that
granted it and ordinary dentists should indicate the number of years of experience.
FDC consists of four fully equipped surgery rooms so that four patients can be
accommodated at any given time. FDC also contains a dental scan room which can be
attended by one patient at a time. The dental scan machine is operated by one of the dentists
of the FDC facility. Normally, a dentist without appointments for a given time slot (say,
between 5 PM and 6 PM) is assigned to the machine by the manager. When that time slot
finishes, another doctor who is free will be assigned.
The staff of FDC is made up of a manager, four nurses (one for each of the four surgery
rooms) and a receptionist who handles registrations and appointments.
An information system is required to keep track of patients, doctors, appointments,
treatments given to patients and payments. The system must also maintain information
about the staff. It has been decided to use an object oriented approach to design and
implement the system.
Task 1
Examine the Object oriented concepts given below. Provide diagrams and code
snippets from suitable specific programming language to supplement your
explanations.
i) Class
ii) Object
iii) Message
iv) Encapsulation
v) Inheritance
vi) Polymorphism
vii) Aggregation/composition
Task 2
Design and build the detailed UML class diagram for the Family Dental Care system.
Your solution should demonstrate all inter-class relationships namely Association,
Inheritance and Aggregation/composition. The classes should include attributes and
methods needed.
Draw the class diagram for the explained system. Including all notations and details and
ensure that the diagram has the required functionalities. Analyze the class diagram
provided above and derive code scenarios related to the UML diagram.
Task 3
Determine and briefly discuss the range of design patterns and describe at least one
design pattern from the three available types of design pattern. Provide suitable UML
diagrams for the given patterns and analyze the relationship between object-oriented
paradigm and design patterns providing a suitable example.
Task 4
Scenario 1
FDC owns a very expensive, state of the art dental scan machine (a device far superior
to a traditional dental X-ray machine) manufactured by Toshiba, Japan. FDC will be
own just one such machine in the foreseeable future. When modeling and
implementing FDC system in software, you must ensure that only one instance of that
machine is created.
You may include suitable attributes for the machine such as serial number, make,
country of origin and cost. Implementation should allow the user to enter details of the
dental scanner and create the sole instance of that machine.
Scenario 02
Below table provides the hierarchy of the Employees and their monthly salary in FDC.
All the Nurses are working under the Dentists and Chamod(Dentist) is working under
the Supuni(Dentist) and Madhavi(Dentist) is working under the Anton(Director).
Develop a system to display the details of all employees and your system should
display which employee is working under which employee clearly.
Scenario 03
Patients who need dental scans are kept in a First in First Out queue. Assume that
you have found an already developed Queue container in a software library. It
provides standard queue operations to insert and remove data (known as enqueue
and deque respectively). However, you need some specific operations such as
search() to look up a particular patient and showAll() to list all the patients in the
queue. These additional operations are not provided by the library unit.
For each of the above scenarios:
Select and Justify the most appropriate design pattern for each of the above given
scenarios then Define and Draw class diagrams for above mentioned design patterns and
develop code for the above scenarios (except for the 3rd Scenario) using an appropriate
programming language. Critically evaluate why you selected the above design patterns
and compare your answer with the range of design patterns available.
Grading Rubric
patterns
P3 Build an application derived from UML class diagrams.
I am very happy to have the opportunity to pursue a course called HND in Computing at
ESOFT. In addition, I really appreciate ESOFT's efforts to help students achieve their goals.
As specially taught the Advanced Programming course and helped to solve all doubts in
relation to the lesson of the students also helped to make the Advanced Programming
assignment systematic through his help, and he helped what he can also, for Nuhman sir I
extend my sincere gratitude.
I. Class.......................................................................................................................... 10
III. Message.................................................................................................................. 14
V. Inheritance ............................................................................................................... 18
1. Association ........................................................................................................... 22
2. Aggregation.......................................................................................................... 23
3. Composition ......................................................................................................... 25
Activity 02 ............................................................................................................................... 26
2.1 Overall Scenario of the System...................................................................................... 26
V. Treatment Class....................................................................................................... 35
Activity 03 ............................................................................................................................... 39
3.1 Discussion about range of Design Patterns with relevant examples of Creational,
Structural and Behavioral Pattern types. .............................................................................. 39
Activity 04 ............................................................................................................................... 56
4.1 Select the Appropriate one for the following Scenario from the Design Patterns
mentioned above and Explain that Accordingly (except for the 3rd Scenario). .................. 56
4.2.1.1 Selected Design Pattern for the Scenario and Reason for that. ........................ 56
4.2.1.2 Implementing a Class for Scan Machines using that Specific Design Pattern 57
4.2.2.1 Selected Design Pattern for the Scenario and Reason for that. ........................ 61
4.2.2.2 System Implementation for the Scenario 02 using the Selected Design Pattern
...................................................................................................................................... 62
I. Queue .................................................................................................................... 65
4.2.3.3 Selected Design Pattern for the Scenario and Reason for that. ........................ 69
Conclusion ............................................................................................................................... 71
Self-Criticism ........................................................................................................................... 72
Gantt Chart ............................................................................................................................... 73
References ................................................................................................................................ 74
Above picture shows the details about how is the Object-oriented programming has been
implemented in the programming languages. According to this, there are some important
structures must need to follow for implement the OOP concept. Such as,
I. Class
II. Object
III. Encapsulation
IV. Inheritance
V. Polymorphism
VI. Abstraction
The diagram above is a class diagram for a class which called customer class. A class always
has its own name and body part, so the name of this class is customer class. Similarly, the
properties and methods for a particular class can be found within its body part. That way, when
look at the diagram for the customer class given above, can see its properties such as id, name,
address, contact_no, NIC and methods such insert, update, delete. Likewise, when a system is
created, multiple classes are created. When the methods of a particular class need to be applied
elsewhere, an object for that class is created and its methods are used. An explanation of this
is given in the following section II. Object. The code for the class created according to the
above diagram is as follows:
Above code snippet for the customer class shows the details about how to create class and also,
which clarifies the boundaries of class. Within the body of the class the properties and methods
will happen based on intention of the class creation.
• Methods: - Each of the primary functions of a class is a method which can be executed
based on the data already stored in that class.
The above class is the class that includes the features for the entity called customer. This can
be understood by observing the diagram above and the name of the class in the codes for the
particular class. Can see that the class in question has been created using the "Public" access
modifier. Also, if want to create a class, the class will be created using the keyword class
following the access modifier, followed by the name of the class. This is how classes are
created. For java language, once the java file is created in the name of the class to be created,
the code to create the class will be written automatically. After that, properties and methods for
the particular class are created within the body part of the class. This can be seen in the image
above.
If taking the codes of the customer class given above, the class contains the properties, the id
in int type and the string type variables name, address, contact_no, NIC have been created
inside the class using the access modifier as "private". The reason why the "private" access
modifier is used here is because the properties of the customer class can only be used within
the particular class and access to them is restricted outside the class. Similarly, the details of
insert, update, delete methods for the particular class created based on the class diagram for the
particular customer class are shown by the code snippet below.
By creating classes in this way, when creating a system, the codes written for that can be
organized and written properly. In addition, when the need arises for a function in a particular
class, they can be easily used with the help of a particular class. Consequently classes, based
on the similarity of codes, lead to maintaining them as a group.
II. Object
An object, in object-oriented programming (OOP), is a type of abstract data generated by a
developer. Which can contain many properties and methods and may even include other
objects. In most programming languages, objects are defined as classes. (Terms, 2021)
Object are giving an organized structure by defining the dataset as custom objects, which is
useful for the programmer to easily create multiple objects with similarity. So, the programmer
can finish his development work very fast by modify existing objects within a program. And
also, the object creating method can be work as encapsulation method, because the object will
be having access modifiers, so the saved data on the object can secure from modified or
destroyed by other functions or methods.
The code snippet above shows the creation of an object belonging to the customer class within
a class called Car_reservation. Where cus_obj is the name of the object, followed by the
"customer " keyword which indicates the type of object. Next, the space for storing the object
in RAM is created using the keyword "new", and then the object belonging to the class is
created by putting the constructor of the particular class (here, customer class). The code
snippet above reveals this. The methods and properties of the class can be manipulated through
the object thus created. Just like how an object is created for a customer class as cus_obj above,
can create such objects for that class under multiple names and get the outputs by executing
the functions of the customer class based on the data provided for the objects.
III. Message
For run a program, the message passing technique has been helping which regard to the
computer science. The triggering of a program sends a message to a process (that can be an
actor or object) and relies on the process and sub-infrastructure to select and execute the actual
code to run. Messaging is different from conventional programming, where a process,
subroutine, or function is executed directly by name.
The following example illustrates how the message exchanged between the classes in a system
when that is created. That is, if consider each of the objects shown in the diagram above to be
objects for each class, then the constructor for the class in which that object is to be created is
needed to create those objects. Such constructors sometimes require the data needed to operate
their classes. The data presented at this time will be transferred from the class in which the
objects were created to the class in which they were created as objects. This is called message
passing.
The code snippet above shows the creation of an object belonging to the class customer inside
the class called Car_reservation. In this case, need to use the constructor of the class to create
the object. The constructor of customer class used for this is as follows;
IV. Encapsulation
The function and status of each object are placed within a separately defined range or class.
Because of this, other object has no authority to access or modify this class, although they can
only call a list of common functions or methods. This feature provides greater program
protection during data encryption and avoids unplanned data corruption.
Figure 10 Encapsulation
According to the Encapsulation theorem, the properties of the specific class should be private
and the methods should be public. Let us give an example of a class created based on this,
As already shown in the class diagram, the customer class contains the properties and methods
of the same name, as well as their access modifiers. Can see that all the properties in the
customer class above are made as private, and all the methods are made as public (That is, the
variables id, name, address, contact_no and NIC of the customer class are "private" and the
insert, update, and delete methods are "public" in the codes for the customer class above as
mention in the class diagram for the customer class). The reason for keeping the properties of
classes "Private" is that the functionality of the methods of that class depends entirely on the
properties of that class. This prevents access to the properties of the class outside the class by
keeping them "Private". In this category the properties of the customer class such as id, name,
address, contact_no and NIC are created as "Private". The properties of the customer class
created to use these are insert, update and delete are made as "Public". With this the methods
can be used inside the customer class as well as outside.
V. Inheritance
Inheritance is the process by which one class inherits the characteristics and patterns of another
class. When a class uses the properties and methods of another class, the owner of those
methods and properties is called the parent class. If a class receives attributes from the parent
class, which is the child class of specific parent class.
According to the above picture, can understand about the inheritance. I.e., the super class
(parent class) has the all properties and methods what their child class needed. All the properties
and methods that can be used by a child class are found in its parent class. But the individual
properties and methods of child classes belonging to the same parent class may vary between
them.
Based on the diagram, the parent class here is a class called vehicle. Inherited, that parent class
should be of the "abstract" type, which can be observed from the diagram and the code provided
above. And its children's classes will be linked to their parent class using the keyword
"extends". This is highlighted in the code snippet above. In this case, the children's classes van,
bus and car are hereditarily related to the vehicle class. This way, children can use the
classroom attributes and methods of their parent class. Accordingly, here classes for children
such as van, car and bus can use the ID and vehicle_type properties of their parent class vehicle
class.
Figure 16 Polymorphism
The image above is a simple illustration of the basis of Polymorphism concepts known as
Override, Overloading. That is, when looking at the image, a device called a phone is a tool
used by one to communicate with another, but now can see different types of phones. Although
all the devices are called as one phone, they differ in terms of the features and quality they
have. This is similar to what is seen in Overloading. That is, overloading distinguishes multiple
functions specified by the same name based on their parameters. Similarly, all phones do the
same thing. This is overriding.
For polymorphism, the concepts of overloading and overriding should be included, as follows
an example for express this.
In the diagram for the above manager class can see that more than one constructor of the
manager class is shown. Overloading is when there is more than one method with the same
name. So, can understand that a function named manager() is created more than once by
observing the diagram for the manager class given above. But the manage () function is
differentiated based on its parameters.
Overloading and overriding are highlighted in the code snippet for the manager class above.
Overriding is the rewriting of existing codes using the same method by using override keyword.
This can be observed above. If the concept of overloading and overriding is found in the classes
when that is created, that may be written following the method called Polymorphism. The same
can be observed here.
Figure 19 Overload
The code snippet above shows how when an object is created for the manager class, operations
are modified by assigning different data as parameters based on its constructors. This can be
observed that the constructors are in the same name, and which are differentiated based on their
parameters. Such a process is called overloading. This feature makes it easier for the developer
to handle the same type of methods. That is, even if the developer creates the same kind of
methods under the same name, the tasks assigned to them will be carried out based on their
parameters. Thus, the developer does not need to have too many methods in mind.
Figure 20 Aggregation/composition
1. Association
Association is a semantic weak relationship (semantic dependence) between objects that are
otherwise unrelated. An association is a "use" relationship between two or more objects in
which objects have their own lifespan but nothing is not owned.
For an example, if take the relationship between the doctor and patient, that can be one-to-
many relationship. Because, the doctor will give treatment for more patients at the same time
the patient also can get diagnose from more doctors. The patient and doctor have a lifespan
separately but no one is owner or parent on the life span. When creating a system in a similar
way the Association relationship between classes is established as shown in the following
diagram.
In the above diagram the vehicle, customer and employee classes are shown to be in
relationship called Association Relationship, with the class called Care_reservation_system.
The diagram for the Association Relationship above shows the relevance of the Car
Reservation System class to the vehicle, customer and employee classes for the implementation
of the Reserve function.
The code snippet shows that the Reserve function for the Car Reservation System class is built
with the help of vehicle, customer and employee classes. In this case, can see above that the
objects of the type of the class are passed as parameters for the function. The above classes
maintain the Association Relationship with the Car Reservation System class for that purpose.
2. Aggregation
Aggregation is a type of association, that special form between two or more objects in which
each object has its own life cycle, but has an ownership. Aggregation is a general whole / part
or parent / child relationship, but which may or may not refer to physical control. The essential
property of the aggregation relationship is that the whole or the parent (i.e., the owner) can be
partial or without the child and vice versa. The child object will not be destroyed as the parent
material is destroyed in this relationship.
The diagram above shows the configuration of the classes Aggregation Relationship called
vehicle and employee. Aggregation Relationship means that the relationship can be separate
from one another without the clauses formed on the basis of that. In this case, the classes shown
above can be created by the employee class without the vehicle class, as well as by the vehicle
class without the employee class. The codes for this are shown below,
The code snippet for the vehicle class above shows the nature of the relationship between the
vehicle and employee classes in the Aggregation Relationship. That is, a parameter pass of
employee type is assigned to the add_driver () method in the vehicle class, which is the
relationship between the two classes. In this case, without functioning that method, can be
perform by another class without one class. One such relationship is Aggregation Relationship.
When creating a system in a similar way the Composition relationship between classes is
established as shown in the following diagram.
In the above diagram, the class composition configuration of vehicle and vehicle_type is
shown. The definition of a Composition relationship is that classes created for a particular
relationship cannot create one without the other. Accordingly, the vehicle class cannot be
created without the vehicle_type class. The codes for this are shown below,
The code snippet for the vehicle class above provides information about the properties of the
vehicle class created based on the Composition Relationship. Here can see that the vehicle_type
type object is the property of this class. This means that without creating an object of the type
vehicle_type class, the functions of that class cannot be properly executed, i.e., another class
cannot perform without one class here. Such a relationship is called Composition Relationship.
The diagram and codes above illustrate this.
I. This includes Managers, Nurses, Receptionists and Doctors when looking at the
company's Employees. To create a profile for them in the system, respectively,
• A profile can be created for them by obtaining their name, address, date of birth,
national ID number and contact number, in general.
II. When the customer (i.e., Patients) of the company register in the system, they have to
provide their name, address, national identity card number and contact number.
III. Apart from this, the entities to be considered for creating the system are as follows:
• Rooms: Two types of rooms are found. They are surgery rooms and dental scan room
respectively. As for the surgery rooms, it has four fully equipped operating rooms so
that four patients can stay at any one time. But the dental scan room can be attended by
one patient at a time.
• Appointment: When the patient is looking for treatment for their disease at the FDC,
he will contact the doctor through a process called Appointment.
• Treatment: The entity called treatment includes the treatments performed in the FDC.
The system created to manage such FDC's operations and assets will be primarily based on the
entities highlighted above. The UML Diagram drawn to create such a system is shown below.
Furthermore, the system is created by giving importance to the entities involved in the diagram.
There are eight primary classes in the diagram, which include diverse relationships such as
association, inheritance, aggregation, and composition. The fundamental functions of each
class are used to examine these connections. All of the above classes are linked to the relevant
database in order to efficiently store class records. The diagram was really helpful in this
regard.
In the example of the Association Relationship shown above, the Association Relationship
between the class FDC Dental Care and the class called Payment is highlighted. Here that is
necessary to should be there a relationship between the two classes in order for the methods of
the class FDC Dental Care to work. Association Relationship is used here for this.
The example given above for Inheritance Relationship is about the Treatment class. That is,
the FDC offers Sophisticated dental implants, Maxillofacial surgeries, Extractions and Nerve
fillings. According to this scenario, by creating a class called Treatment, the common attributes
for the above four treatments are stored in one place and the class is seen as the parent class for
the 4 treatments. Inheritance Relationship is used as shown in the picture above to highlight
the relationship between the classes in such a relationship.
The above example highlights the existence of Room and Employee classes in Aggregation
Relationship. This means that the Room and Employee classes can be interdependent and at
the same time can be separate from one another. The relationship method used for that
condition is Aggregation Relationship. Here can be created Employee class without Room class
as well as Room class without Employee class.
In the example for the above Composition Relationship, the Relationship between the classes
Appointment and Treatment is shown. In this, a process called Appointment is essential for the
treatment to be created. That is, cannot create another class without one of these classes.
Composition Relationship is used to refer to such a relationship.
By looking at the class diagram for the above Employee class, can know that the Employee
class is the parent class for the other Manager, Doctor, Nurse and Receptionist classes. The
created codes based on this are as follows:
The Doctor class shown above already has an inheritance relationship with the Employee class.
According to the given Scenario, there are two types of Doctors in FDC. Thus, the dentist and
consultant classes have been created as doctor class's children classes with the Doctor class
include their common characteristics, and each of them classes having special features.
A total of two types of payment are required from the patient when the patient first registers
with the FDC and receives an appointment for treatment. Thus, the inheritance relationship of
these two classes with this payment class is maintained by creating a class called payment to
include the common properties of both Register payment and Treatment payment classes. Thus,
the classes shown above were coded accordingly.
In the given scenario that is mentioned that there are two types of rooms in FDC. Thus, two
classes, surgery_room and scan_room, were created and a parent class called room class was
created to cover their common characteristics. The codes for this can be seen in the image
above.
V. Treatment Class
The given scenario states that there are 4 types of treatments in FDC. Thus, a parent class called
treatment has been created to cover the common features of the 4 treatments, and the above 4
treatments have been created as separate children's classes to be in inheritance relationship with
the parent class. The codes for this are shown in the image above.
In the provided scenario, this is stated that the scan room can only be used by one person at a
time. From this it can be seen that there is a correlation between the two parent classes, the
employee class and the room class. But in relation to that, one class can be created without the
other, so this is an aggregation-based relationship The codes for the room class thus created are
given in the image above.
If Registration Payment must be made, there should be a patient before that can occur. Thus,
the two classes are in a composition relationship. Accordingly, in the Registration Payment
class the object for the patient class is seen as an asset. Likewise, in order for the above
Registration Payment to take place, all the properties of the particular class must be in order.
Therefore, the above two classes are found in a close composition relationship. The codes for
this are shown in the image above.
Based on the scenario thus provided, the management system for FDC was developed as above
using the UML diagram created.
• Common platform for developers: - Design patterns provide a standard terminology, and
they are appropriate for a particular situation. For example, if take a
singleton design method, that refers to the use of a single object, so all
developers who are familiar with the single design form will use a single
object, and when talking to other programmers about their software the
software can be reported to have been developed by using the singleton
pattern method.
• Best Practices: - Design patterns have been around for a long time, and they are providing
excellent solutions to some common problems encountered during
software development. Because of this is that learning these formats
helps inexperienced developers to learn software design easily and
quickly.
Singleton Pattern
If consider a class that has only one instance and provides a global point of access to
that, can say, that class has been coded using Singleton Pattern. I.e., a class must ensure
that only single instance should be created and single object can be used by all other
classes.
Prototype Pattern
Cloning of an existing object, alternative for create new one and also can be
customizable based on the requirement, if any pattern define like this, that called
Prototype Pattern. This pattern should be followed, if the cost of creating a new object
is luxurious and resource intensive.
4
Advantage of Prototype Pattern
• Needs of sub-classing has been reduce by this.
• Complexities of creating objects has been hides by this.
• The clients can get new objects without knowing which type of object that will be.
• Add or remove objects at runtime, that allows.
5
Advantage of Builder Design Pattern
• This differentiates construction and representation of an object clearly.
• This provides better control over construction process.
• This supports to change the internal representation of objects.
(Javatpoint, 2021)
Bridge Pattern
Simply "decouple the functional abstraction from the implementation such that the two
can vary independently," according to the Bridge Pattern.
Composite Pattern
"Allow clients to work in a general fashion on objects that may or may not represent a
hierarchy of objects," states a Composite Pattern.
Facade Pattern
A Facade Pattern is defined as "merely providing a uniform and simplified interface to
a group of interfaces in a subsystem, thereby hiding the subsystem's intricacies from the
client." Facade Pattern, in other terms, is a higher-level interface that makes a sub-
system easier to use. Every Abstract Factory is essentially a form of Facade.
5
Flyweight Pattern
"To reuse already existing similar sort of things by storing them and generate new object
when no matching object is discovered," according to a Flyweight Pattern.
(Javatpoint, 2021)
Command Pattern
According to the Command Pattern, "Encapsulate a request in an object and deliver that
2 to the invoker object as a command. The invoker object searches for a relevant object
that can handle this command and passes the command to that object, which then
performs the command ". It's also referred to as an activity or a transaction.
Interpreter Pattern
"To define a representation of grammar of a particular language, as well as an interpreter
that uses this representation to interpret sentences in the language," according to an
Interpreter Pattern. In general, the Interpreter pattern can only be used in a restricted
number of situations. The Interpreter pattern can only be discussed in terms of formal
grammars, although there are superior solutions in this field, which is why it is not often
3 utilized. This pattern can be used to parse phrases written in basic grammars and, on
rare occasions, simple rule engines.
Iterator Pattern
Iterator Pattern is used "to progressively retrieve the constituents of an aggregate object
without disclosing its underlying implementation," according to GoF. Cursor is another
name for the Iterator pattern. Now utilizing Iterator instead of Enumeration in the
collection structure.
4
Mediator Pattern
"To define an entity that captures how a group of objects communicate," states the
5 Mediator Pattern. When first start developing, create a few classes that interact with one
another to produce outcomes.
Memento Pattern
"To restore the state of an item to its prior state," according to a Memento Pattern.
However, that must do so without breaking Encapsulation. In the event of a mistake or
failure, such a scenario is beneficial. Token is another name for the Memento pattern.
One of the most often used operations in an editor is undo, sometimes known as
backspace or ctrl + z. The undo action is implemented using the Memento design
6
pattern. This is accomplished by storing the object's current state as that change.
Observer Pattern
"Just construct a one-to-one dependence so that when one object changes state, all its
dependents are alerted and changed immediately," according to the Observer Pattern.
7
Dependents or Publish-Subscribe are other names for the observer design.
State Pattern
"The class behavior changes dependent on its state," according to a State Pattern.
Generate objects that represent distinct states and a context object whose behavior
changes as its state object changes in State Pattern. Objects for States is another name
for the State Pattern.
8
Strategy Pattern
"Defines a family of functions, encapsulates each one, and makes them
interchangeable," according to a Strategy Pattern. Policy is another name for the
Strategy Pattern.
Template Pattern
"Just specify the skeleton of a function in an operation, deferring some stages to its
subclasses," according to the Template Pattern.
10
Advantage of Template Pattern
• This is a widely used approach for recycling code. This is only the most significant
advantage.
(Javatpoint, 2021)
The image above shows the primary three sections of Design Patterns as Creational, Structural
and Behavioral and their sub-sections. And the relationship between the OOP concept and
Design patterns is illustrated below, using the sub design patterns marked by the green check
boxes.
This pattern uses a single class that is in charge of creating an object while ensuring that only
one object is generated. This class provides a method to access its single object, which may be
accessed without having to initialize the class's object. (Tutorialspoint.com, 2021)
The code snippet above shows the codes for the Singleton Design Pattern. The purpose of the
Design Pattern is to use only one instance for the class. For this, when the constructor for a
particular class is created, that can be seen in the image above that it was created using a private
access modifier. Thus, the object for the particular class cannot be created inside any external
class. Then, an object for that class is created inside the class, and a method is created inside
the class that can return that with a static method called getInstance(). This way, if want to
access the object of the class outside the class, can only access that by calling the getInstance()
function. Through this, ensures that only object created within this class are used outside.
Figure 52 Output
The image above shows how Hello World is printed as code in the showMessage () method in
the SingleObject class.
• Can see the created class object in the pictures above. Coding using this object is an OOP
concept-based feature. Thus, the OOP concept is used in design patterns.
• Above can see that it is coded based on classes and used in the design pattern. This is also
an OOP concept-based feature.
Thus, design patterns are coded and implemented based on the OOP concept. Of this can be
found by understanding the structure of the example as Singleton Design Pattern.
The Employee class based on the Composite Pattern is shown in the code snippet above. In this
can observe that the properties of the particular class are "Private" and the methods are
"Public". In this way, the properties, name, dept, salary and subordinates of the employee class
are created as "Private" and access to them is restricted and protected outside the employee
class. Similarly, Employee(), add(), remove(), getSubordinates() and toString() of the
respective Employee class methods are made "public" so that they can be able to use both inside
and outside the Employee class.
The add() and remove() methods created for the respective employee class perform their
function by obtaining an employee type parameter, as well as the getSubordinates() function,
which can return a list of employee type, Can observe in the code snippet above that a method
called toString() has been created which is a string type returnable.
The code snippet above shows the codes for the class implementing the Composite design
pattern. In this case, can see above those various objects have been created for the Employee
class. Can also see that the add () method of the relevant Employee class is called using the
created objects. And the reason why such activity is carried out is to show the employees which
employee they are working under. In this case, when the objects for the Employee class are
created and the add () method of the Employee class is called using the created objects, the
activity related to the OOP concept called message passing is performed.
Structure:
The code snippet above provides information about the Observer Class. The class in question
has been created as an unfinished class using the keyword "Abstract". That is, the class must
be completed by its children class.
The code snippet above provides data about the children classes of the observer class. In
addition, they can detect the nature of the inheritance relationship and, when creating such a
class using the Observer Design Pattern, observe that the observer class's update () method is
overridden.
Conclusion: Thus, the use of the OOP concept is evident when one observes the codes written
according to singleton, composite and observer patterns, which are subdivisions from the main
sections of the design pattern, Creational, Structural and Behavioral. Thus, from the above
study it can be seen that the OOP concept is intertwined in the design pattern.
4.2.1.1 Selected Design Pattern for the Scenario and Reason for that.
According to the scenario 01, when creating a class for managing FDC scan machines on a
particular system, the object for that class must not be created outside. That is, only one object
should be used for that class. Based on this, it was decided that it would be optimal to create
the class using a design pattern called Singleton. When researching the design pattern known
as Singleton, As stated in Section 3.1.1 Design Patterns,
Structure:
The diagram shown above is a good example to understand the Singleton Design Pattern. If the
object for the Singleton class is to be created externally, that can only be created with the help
of a static function called “instance ()” as shown in the above diagram, considering the class
outer from the Singleton class referred to as the client. A function is a method created to return
an object to the Singleton class. By doing so, the Singleton class will be prevented from creating
more than one object, and that single object created inside for the Singleton class will be used
everywhere.
Figure 59 Class Diagram for the Scan_Machine class, according to the Singleton pattern
In the diagram for the scan machine class above, can see that the object for that class is created
using a private access modifier named "instance". Can also see that a static function called
"getInstance ()" has been created to return the object. Based on this, the codes for the class will
be written. The codes for the scan machines class created on this basis are as follows:
4.2.1.2 Implementing a Class for Scan Machines using that Specific Design Pattern
Above are the codes and diagrams for the Scan Machine Class, in which can see that the
constructor created for that class is private. This prevents object creation for Scan Machine
Class in inside of other classes. Evidence for this is given below.
The code snippet above shows an error that occurred while trying to create a new object for the
class Scan Machine inside another class. This is due to the fact that the constructor of the Scan
Machine class is private.
The code snippet above shows an object created for Scan Machine Class within another class
using a static method created to return the object created for that class within the Scan Machine
Class. This means that the same instance object created inside the Scan Machine Class will be
stored inside the SM object. Through this only one object will be used for the particular Scan
Machine Class.
Thus, Scan Machine Class, which follows the Singleton Design Pattern, meets the expectations
of Scenario 01. Thus, the Singleton Design Pattern is suitable for creating a system in which
classes can communicate using a single object.
Justification: By creating a class for the particular scan machine based on the Singleton Design
Pattern, only the object for the particular class created within the particular class can be
executed for use in other classes. That is, creating a constructor for a class called scan machine
using a private access modifier to prevent the creation of an object for that class in external
classes. Then, by creating a static method that can return the specific object created within the
class for that particular class, that single object can only be used elsewhere to access the
properties and methods of that class. Thus, the Singleton Design Pattern is the best solution for
creating a class based on Scenario 01.
Note: working under the Dentists and Chamod (Dentist) is working under the Supuni (Dentist)
and Madhavi (Dentist) is working under the Anton (Director).
According to this, when researching the design pattern known as Composite Pattern, As stated
in Section 3.1.1 Design Patterns,
Definition: A structural pattern that modifies the structure of an item is known as a composite
design pattern. This pattern is best used when working with things that are organized in a tree-
like structure. Each node/object in that tree (save the root node) is either a composite or a leaf
node. Clients can use the composite pattern to treat individual items and compositions
consistently.
Structure:
Figure 66 The structure of the application created using the composite pattern
4.2.2.2 System Implementation for the Scenario 02 using the Selected Design Pattern
Employee class is implemented as per the instructions and class diagram given in Scenario 02
above.
Can understand the properties created for the Employee class according to the class diagram
given in Scenario 02 by observing the image above. In this, can observe that the class is created
with the same names given in the diagram and using the same access modifier mentioned. In
addition, can see in the image above that the properties of a particular class are initialized by
creating a constructor for that particular class.
The balance part of the Employee class is shown in the image above. In that, it is shown that
the methods mentioned in the given diagram have been created in the class. Can see that the
methods created under the same name mentioned in the diagram are created. Can also see that
their access modifiers are "Public" as mentioned in the diagram.
The biggest expectation in the given Scenario 02 is that when viewing the FDC employees,
the system should systematically show which employees are working under which staff. Based
on this, the function created in the relevant Employee class is shown in the image above.
The code snippet above shows the codes written to insert the Employees based data specified
in the table provided by Scenario 02 into the system. In addition, they are displayed according
to the status of the employees, and the codes for performing them systematically when inserting
them into the list are shown. Also, the output for the above implementation is shown in the
following figure.
Justification: The Composite pattern allows to create a tree-like layered recursive object
structure. That is, as stated in Scenario 02, this tree-like structure would be perfect for showing
which employee is snowing under which employee. With this, the status of their branches can
be displayed systematically from top to bottom. This is why the Composite pattern is used to
solve the given scenario issue.
In the diagram above, the tree-structure for the employee class drawn based on the given
scenario is shown. Also, since this is also a tree-structure style, the composite design pattern
was determined to be the best way to create such an employee class.
4.2.3 Scenario 03
Patients who need dental scans are kept in a First in First Out queue. Assume that you have
found an already developed Queue container in a software library. It provides standard queue
operations to insert and remove data (known as enqueue and deque respectively). However,
you need some specific operations such as search() to look up a particular patient and showAll()
to list all the patients in the queue. These additional operations are not provided by the library
unit.
This function is used to add a new item to the back of the queue and
enqueue(item)
requires the item for this and does not return anything.
Removes the front item from the queue. This does not require parameters
dequeue()
and returns the item. The queue has been modified.
Checks whether the queue is empty. That does not require parameters and
isEmpty()
will provide Boolean value.
Provides the number of items in the queue. This does not require
size()
parameters and provides an integer.
(Runestone academy, 2021)
The code snippet above shows the Properties created for the Patient class and its properties
initialized by creating the constructor for that class. Also, this can be observed that all the
properties are "Private" and the methods are "Public". That is, this shows that the Encapsulation
method of the OOP concept has been followed.
The code snippet above shows the methods written for inserting patients and viewing them
within the patient class. The following figure shows information about the list used to store the
patients thus inserted.
As mentioned in Scenario 03, can see that the class diagram created for the patient class given
above shows methods called search() and display() (showAll()). Can see in the already
provided image that a method called display () is implemented to display the Patients inserted
in the list. Evidence for the implementation of the search () function in the patient class is as
follows:
4.2.3.3 Selected Design Pattern for the Scenario and Reason for that.
According to Scenario 03, the Iterator Pattern is determined to be optimal for creating a
patient class, which will allow patients to make appointments according to their registered order
(based on the queue method) and to make new registrations.
According to this, when researching the design pattern known as Iterator Pattern, As stated in
Section 3.1.1 Design Patterns,
Definition: In the Java and.Net programming environments, the iterator pattern is a widely
used design pattern. This technique is used to access the components of a collection object in
a sequential manner without knowing its underlying representation.
As it separates from the collection of items, the Iterator Design Pattern graphic shows a
common interface for the client. getIterator() is activated by the patient, and it gives a way to
return to its collection. Each Patient is responsible for creating a getIterator in order to revive
its collection of items. Next() / hasNext() provides a number of modes for traversing and
altering the collection, as well as search and removal features.
That is, the Iterator Design Pattern has its own set of methods for retrieving the given data in
order (first in first out). This is exactly what is expected of Scenario 03. That is, according to
the order in which the patients are registered, the Design Pattern will be relevant to get them
from the employee list and create an appointment through the Next() / hasNext() methods of
the Iterator Design Pattern.
Apart from these, the Iterator Design Pattern is optimized for Scenario 03, as it provides the
optimal solution for retrieving patients from the list where their data is stored in the orders in
which they are registered, with the expected search () and showAll () function in Scenario 03.
The task entails the development of a management system for the FDC. During the operation,
the system creation process is initiated depending on the user needs. The design pattern
approaches were applied during the operation, which is the highlight of the assignments. As a
consequence, a unique coding experience was created. During the course of this task, I also
learnt how to adjust to various scenarios.
In addition, the dental care administration system was created in the Java programming
language. It was a console program as well. The challenge of detecting and troubleshooting
system faults was extremely challenging. However, towards the conclusion of the development
process, it was discovered that the debugging expertise had vastly improved.
I was able to get knowledge with terminal programs and cmd by working on such an
assignment. Furthermore, the Advanced Programming subject structure includes a highly
extensive algorithm curriculum, which allows students to obtain more expertise with
algorithms.
• Can understand how to write code in proper manner (organized) through the experience
of solving errors.
• I have learned about how to identify the error in the written code by using cmd output.
• I have learned about how to design the minimal user interface in console application.
• I have learned about how to write code according to the Design pattern and how to
implement that.
So, this is a good opportunity for get more knowledge about programming and this is seen as
way for invent more interesting and important things in IT society.