0% found this document useful (0 votes)
43 views89 pages

1164-1619624869751-40 - Advanced Programming Reworded 2021 (K.sathurcigan)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views89 pages

1164-1619624869751-40 - Advanced Programming Reworded 2021 (K.sathurcigan)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)


INTERNAL VERIFICATION – ASSESSMENT DECISIONS

Programme title HND in Computing - Application Dev / Software Eng. Pathway

Assessor Mr. Nuhman Internal Verifier Mr. Thanuluxshan


Unit 20 – Advance Programming
Unit(s)

Assignment title Information System for Family Dental Care (FDC)

Student’s name Mr. Kamalendran Sathurcigan


List which assessment Pass Merit Distinction
criteria the Assessor has
awarded.
INTERNAL VERIFIER CHECKLIST

Do the assessment criteria awarded


match those shown in the
assignment brief? Y/N

Is the Pass/Merit/Distinction grade


awarded
Y/N
justified by the assessor’s comments on
the
student work?
Has the work been
assessed accurately? Y/N

Is the feedback to the student:


Give details: Y/N
• Constructive?
Y/N
• Linked to relevant assessment criteria?
• Identifying opportunities Y/N
for improved
performance?
• Agreeing actions? Y/N

Does the assessment decision


need amending? Y/N

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date
Confirm action
completed
Remedial action taken
Give details:

Assessor signature Date

Internal Verifier Date


signature
Programme Date
Leader signature
(if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID Mr. Kamalendran Sathurcigan (BAT/A-006688)

Unit Title Unit 20 – Advanced Programming


Assignment Number 1 Assessor Mr. Nuhman
20/01/2022 Date Received
Submission Date 1st submission
Date Received 2nd
Re-submission Date submission
Assessor Feedback:

LO1. Examine the key components related to the object orientated programming paradigm,

analysing design pattern types.


Pass, Merit & Distinction Descripts P1 M1 D1

LO2. Design a series of UML class diagrams


Pass, Merit & Distinction Descripts P2 M2 D2

LO3. Implement code applying design patterns

Pass, Merit & Distinction Descripts P3 M3 D3

LO4. Investigate scenarios with respect to design patterns


Pass, Merit & Distinction Descripts P4 M4 D4

Grade: Assessor Signature: Date:


Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

Signature & Date:

* 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

Feedback: Student to Assessor


Mr. Nuhman was very helpful to me in doing this work and was very friendly and he taught
us well. Through his lecture I was able to understand many areas related to the coding
system. This is an opportunity to learn how to use the Java console application

Assessor Date
signature

Student [email protected] Date 20/01/2022


signature
Pearson Higher Nationals in
Computing
Unit 20 – Advance Programming
General Guidelines

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.

Word Processing Rules

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:

1. It is strictly prohibited to use textboxes to add texts in the assignments,


except for the compulsory information. eg: Figures, tables of
comparison etc. Adding text boxes in the body except for the before
mentioned compulsory information will result in rejection of your work.
2. Carefully check the hand in date and the instructions given in the
assignment. Late submissions will not be accepted.
3. Ensure that you give yourself enough time to complete the assignment by the due
date.
4. Excuses of any nature will not be accepted for failure to hand in the work on time.
5. You must take responsibility for managing your own time effectively.
6. If you are unable to hand in your assignment on time and have valid
reasons such as illness, you may apply (in writing) for an extension.
7. Failure to achieve at least PASS criteria will result in a REFERRAL grade.
8. Non-submission of work without valid reasons will lead to an automatic
RE FERRAL. You will then be asked to complete an alternative
assignment.
9. If you use other people’s work or ideas in your assignment, reference
them properly using HARVARD referencing system to avoid plagiarism.
You have to provide both in-text citation and a reference list.
10. If you are proven to be guilty of plagiarism or any academic misconduct,
your grade could be reduced to A REFERRAL or at worst you could be
expelled from the course
Student Declaration

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.

1. I know that plagiarism is a punishable offence because it constitutes theft.

2. I understand the plagiarism and copying policy of Edexcel UK.

3. I know what the consequences will be if I plagiarise or copy another’s work in


any of the

assignments for this program.

4. I declare therefore that all work presented by me for every aspect of my


program, will be my own, and where I have made use of another’s work,
I will attribute the source in the correct way.
5. I acknowledge that the attachment of this document signed or not,
constitutes a binding agreement between myself and Pearson, UK.
6. I understand that my assignment will not be considered as submitted if
this document is not attached to the assignment.

Student’s Signature: Date:


[email protected] 20/01/2022
Higher National Diploma in Business
Assignment Brief
Student Name /ID Number Mr. Kamalendran Sathurcigan (BAT/A-006688)

Unit Number and Title Unit 20 – Advance Programming

Academic Year 2021/22


2018/19

Unit Tutor Mr.Nuhman

Assignment Title

Issue Date 22/05/2021

Submission Date 20/01/2022

IV Name & Date

Submission format

The submission is in the form of an individual written report about. This


should be written in a concise, formal business style using single spacing
and font size 12. You are required to make use of headings, paragraphs and
subsections as appropriate, and all work must be supported with research
and referenced using the Harvard referencing system. Please also provide
an end list of references using the Harvard referencing system. Please note
that this is an activity-based assessment where your document submission
should include evidences of activities carried out and of team working. To
carry out activities given on the brief, you are required to form groups,
comprising not exceeding 15 individuals.

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.

Emp Id Name Position Salary


A001 Anton Director 1,000,000 LKR
A002 Chamod Dentist 600,000 LKR
A003 Supuni Dentist 600,000 LKR
A004 Madhavi Dentist 600,000 LKR
A005 Piyal Nurse 200,000 LKR
A006 Kamal Nurse 200,000 LKR
A007 Kapila Nurse 200,000 LKR

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

Grading Criteria Achieved Feedback

LO1 Examine the key components related to the


object-orientated programming paradigm,
analyzing design pattern types

P1 Examine the characteristics of the


object-orientated paradigm as well as the various class
relationships.
M1 Determine a design pattern from each of the
creational, structural and behavioral pattern
types.

D1 Analyse the relationship between the


object-orientated paradigm and design patterns.

LO2 Design a series of UML class diagrams

P2 Design and build class diagrams using a UML tool.

M2 Define class diagrams for specific design patterns using a


UML tool.
D2 Analyse how class diagrams can be derived from a given
code scenario using a UML tool.
LO3 Implement code applying design

patterns
P3 Build an application derived from UML class diagrams.

M3 Develop code that implements a design pattern for a


given purpose.
D3 Evaluate the use of design patterns for the given
purpose specified in M3.

LO4 Investigate scenarios with respect to design Patterns

P4 Discuss a range of design patterns with relevant


examples of creational, structure and behavioral pattern
types.

M4 Reconcile the most appropriate design


pattern from a range with a series of given scenarios.

D4 Critically evaluate a range of design patterns against


the range of given scenarios with justification of your
choices.
Acknowledgement
First of all, I would like to express my first gratitude to Esoft and all its employees for being
the source of the life of many students by giving degree as external. I am happy that my
software engineer dream will being fulfilled by Esoft. I express my gratitude to my parents,
colleagues, especially Esoft lecturers for this. And I am happy for Esoft gives a way of
obtaining a British degree in Sri Lanka.

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.

K. Sathurcigan Unit 40 Advanced Programming 1


Table of Contents
Acknowledgement ..................................................................................................................... 1
Table of Contents ....................................................................................................................... 2
Table of Figures ......................................................................................................................... 5
Table of Tables .......................................................................................................................... 8
Activity 01 ................................................................................................................................. 9
1.1 Object Oriented Programming ......................................................................................... 9

1.1.1 Characteristics of OOP ........................................................................................... 10

I. Class.......................................................................................................................... 10

II. Object ...................................................................................................................... 13

III. Message.................................................................................................................. 14

IV. Encapsulation ......................................................................................................... 16

V. Inheritance ............................................................................................................... 18

VI. Polymorphism ........................................................................................................ 20

VII. Aggregation/composition ..................................................................................... 22

1. Association ........................................................................................................... 22

2. Aggregation.......................................................................................................... 23

3. Composition ......................................................................................................... 25

Activity 02 ............................................................................................................................... 26
2.1 Overall Scenario of the System...................................................................................... 26

2.1.1 UML Class Diagram for the Scenario .................................................................... 28

2.1.1.1 Association Relationship Evaluation ............................................................... 29

2.1.1.2 Inheritance Relationship Evaluation ................................................................ 30

2.1.1.3 Aggregation Relationship Evaluation .............................................................. 30

2.1.1.4 Composition Relationship Evaluation ............................................................. 31

2.2 Build an Application derived from UML Class Diagrams. ........................................... 32

2.2.1 Classes Created based on Inheritance ..................................................................... 32

I. Employee Class ........................................................................................................ 32

K. Sathurcigan Unit 40 Advanced Programming 2


II. Doctor Class ............................................................................................................ 33

III. Payment Class ........................................................................................................ 34

IV. Room Class ............................................................................................................ 35

V. Treatment Class....................................................................................................... 35

2.2.2 Classes Created based on Aggregation ................................................................... 36

I. Room Class ............................................................................................................... 36

2.2.3 Classes Created based on Composition .................................................................. 37

I. Appointment Class ................................................................................................... 37

II. Registration Payment Class ..................................................................................... 38

Activity 03 ............................................................................................................................... 39
3.1 Discussion about range of Design Patterns with relevant examples of Creational,
Structural and Behavioral Pattern types. .............................................................................. 39

3.1.1 Design Patterns ....................................................................................................... 39

3.1.1.1 Usages of Design Patterns ............................................................................... 39

3.1.1.2 Types of Design Patterns ................................................................................. 40

1. Creational Design Patterns ................................................................................... 40

2. Structural Design Patterns.................................................................................... 42

3. Behavioral Design Patterns .................................................................................. 45

3.2 Relationship between OOP and Design Patterns ........................................................... 49

3.2.1 Singleton Design Pattern..................................................................................... 49

How the Design Pattern relate with OOP concepts ................................................. 51

3.2.2 Composite Design Pattern................................................................................... 51

How the Design Pattern relate with OOP concepts ................................................. 53

3.2.3 Observer Design Pattern ..................................................................................... 54

How the Design Pattern relate with OOP concepts ................................................. 55

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

K. Sathurcigan Unit 40 Advanced Programming 3


4.1.1 Scenario 01.............................................................................................................. 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 Scenario 02.............................................................................................................. 60

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

4.2.3 Scenario 03.............................................................................................................. 65

4.2.3.1 Queue Operations............................................................................................. 65

I. Queue .................................................................................................................... 65

II. Major Operation of the Queue ............................................................................ 66

4.2.3.2 System Implementation According to the Scenario 03.................................... 67

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

K. Sathurcigan Unit 40 Advanced Programming 4


Table of Figures
Figure 1 Symbols of Object-oriented Programming................................................................ 10
Figure 2 Diagram for Class ...................................................................................................... 11
Figure 3 Usages of the Class in OOP....................................................................................... 11
Figure 4 Methods of the Customer Class................................................................................. 12
Figure 5 Example for Object.................................................................................................... 13
Figure 6 Example for Object in code wise............................................................................... 14
Figure 7 Message Passing ........................................................................................................ 15
Figure 8 Example for Message Passing between the classes ................................................... 15
Figure 9 Example for Constructor ........................................................................................... 15
Figure 10 Encapsulation .......................................................................................................... 16
Figure 11 Diagram for Encapsulation ...................................................................................... 16
Figure 12 Example for Encapsulation...................................................................................... 17
Figure 13 Example for Inheritance .......................................................................................... 18
Figure 14 Diagram for Inheritance .......................................................................................... 18
Figure 15 Example for Inheritance .......................................................................................... 19
Figure 16 Polymorphism.......................................................................................................... 20
Figure 17 Diagram for Polymorphism ..................................................................................... 20
Figure 18 Example for Polymorphism..................................................................................... 21
Figure 19 Overload .................................................................................................................. 21
Figure 20 Aggregation/composition ........................................................................................ 22
Figure 21 Real world Example for Association ....................................................................... 22
Figure 22 Diagram for Association Relationship .................................................................... 23
Figure 23 Code for Association Relationship .......................................................................... 23
Figure 24 Diagram for Aggregation Relationship ................................................................... 24
Figure 25 Code for Aggregation Relationship ......................................................................... 24
Figure 26 Diagram for Composition Relationship................................................................... 25
Figure 27 Code for Composition Relationship ........................................................................ 25
Figure 28 UML Class Diagram................................................................................................ 28
Figure 29 Association Relationship Example .......................................................................... 29
Figure 30 Inheritance Relationship Example ........................................................................... 30
Figure 31 Aggregation Relationship Example ......................................................................... 31
Figure 32 Composition Relationship Example ........................................................................ 31

K. Sathurcigan Unit 40 Advanced Programming 5


Figure 33 Part of the Employee class-based UML diagram .................................................... 32
Figure 34 Employee Class ....................................................................................................... 32
Figure 35 Part of the Doctor class-based UML diagram ......................................................... 33
Figure 36 Doctor Class ............................................................................................................ 33
Figure 37 Part of the Payment class-based UML diagram ...................................................... 34
Figure 38 Payment Class ......................................................................................................... 34
Figure 39 Part of the Room class-based UML diagram .......................................................... 35
Figure 40 Room Class .............................................................................................................. 35
Figure 41 Part of the Treatment class-based UML diagram .................................................... 35
Figure 42 Treatment Class ....................................................................................................... 36
Figure 43 Part of the Room class-based UML diagram .......................................................... 36
Figure 44 Room Class .............................................................................................................. 37
Figure 45 Part of the Appointment class-based UML diagram ............................................... 37
Figure 46 Appointment Class .................................................................................................. 37
Figure 47 Part of the Registration Payment class-based UML diagram .................................. 38
Figure 48 Registration Payment Class ..................................................................................... 38
Figure 49 Types of Design Patterns ......................................................................................... 49
Figure 50 Code for Singleton Design Pattern .......................................................................... 50
Figure 51 Outside from the Class ............................................................................................ 50
Figure 52 Output ...................................................................................................................... 51
Figure 53 Example for Composite design pattern ................................................................... 52
Figure 54 Application class for Composite design pattern ...................................................... 53
Figure 55 Diagram for Observer Design Pattern ..................................................................... 54
Figure 56 Observer Class ......................................................................................................... 54
Figure 57 Children classes of Observer class .......................................................................... 55
Figure 58 Diagram for Singleton Design Pattern .................................................................... 56
Figure 59 Class Diagram for the Scan_Machine class, according to the Singleton pattern .... 57
Figure 60 Diagram for Scan Machine Class ............................................................................ 57
Figure 61 Code for the Scan Machine Class ............................................................................ 58
Figure 62 Evidence for prevention of object creation ............................................................. 58
Figure 63 Confirmation for single object has been used for Scan Machine Class .................. 59
Figure 64 Class diagram for Employee ................................................................................... 60
Figure 65 Diagram for Composite Design Pattern .................................................................. 61
Figure 66 The structure of the application created using the composite pattern ..................... 62

K. Sathurcigan Unit 40 Advanced Programming 6


Figure 67 Property Creation for the Class ............................................................................... 62
Figure 68 Methods of the Class ............................................................................................... 63
Figure 69 Function for Print the Employees ............................................................................ 63
Figure 70 The Given Data insertion......................................................................................... 64
Figure 71 Output for the Implementation ................................................................................ 64
Figure 72 Tree Structure for the given Scenario ...................................................................... 65
Figure 73 Basic operations of the QUEUE .............................................................................. 66
Figure 74 Property Creation for the Class ............................................................................... 67
Figure 75 Code for Insert & View Patients ............................................................................. 67
Figure 76 Created List for store the Patients Details ............................................................... 68
Figure 77 Diagram for the Patients class ................................................................................. 68
Figure 78 search() Method ....................................................................................................... 68
Figure 79 Queue operation based on Scenario 03 ................................................................... 69
Figure 80 Diagram for Iterator Design Pattern ........................................................................ 70

K. Sathurcigan Unit 40 Advanced Programming 7


Table of Tables
Table 1 Creational Design Patterns.......................................................................................... 40
Table 2 Types of Structural Design Patterns ........................................................................... 43
Table 3 hierarchy of the Employees and their monthly salary in FDC ................................... 60
Table 4 Operation of the Queue ............................................................................................... 66
Table 5 Gantt Chart .................................................................................................................. 73

K. Sathurcigan Unit 40 Advanced Programming 8


Activity 01
1.1 Object Oriented Programming
OOP is a type of approach in programming. Joining is mainly considered here. i.e., already one
program has some important codes. When need to solve a problem, that time the current
program connects with oldest program and use their codes to solve the problem. This technique
is making the code pretty much short and well organized one.

Advantages of Object-Oriented Programming


• Due to mitigation and incorporation, OOP simplifies administration.
• OOP represents the real world which is make this easy to understand.
• Though the object fully inside of program, which can usable in other programs again.

Disadvantages of Object-Oriented Programming


• Object-oriented programs are slow and use large amount of memory.
• Over-centralization
• If the main program unfortunately deleted, then other jointly created programs also will
affected.

Programming languages that use OOP


1. Java
2. JavaScript
3. Python
4. C++
5. Visual Basic .NET
6. Ruby
7. Scala
8. PHP

K. Sathurcigan Unit 40 Advanced Programming 9


Figure 1 Symbols of Object-oriented Programming

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

These thing detailly explained below with suitable examples.

1.1.1 Characteristics of OOP


I. Class
Class is work as a template for creating or instantiating, specific objects within a program.
which is used for describe one or more objects in object-oriented programming. The Properties
of a particular class can be used by calling a class by object or by its name into another class.

Below is an example in the form of a diagram, for this.

K. Sathurcigan Unit 40 Advanced Programming 10


Figure 2 Diagram for Class

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:

Figure 3 Usages of the Class in OOP

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.

K. Sathurcigan Unit 40 Advanced Programming 11


• Properties: - The variable (property) is the feature that is used to temporarily store the data
that is mainly needed to accomplish the purpose for which the class was created.

• 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.

Figure 4 Methods of the Customer Class

K. Sathurcigan Unit 40 Advanced Programming 12


The code snippet given above shows that the methods for the customer class have been
developed using the class diagram for the customer class given above. That is, if we take the
methods of the customer class, they are functions named insert, update and delete respectively.
These can be created using the "public" access modifier (marked "+" in the class diagram) as
specified in the class diagram for the customer class and without any returns. The insert, update
and delete methods for the customer class are created using the "public" access modifier,
because that the methods can be used not only inside the class but also outside.

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.

Figure 5 Example for Object

K. Sathurcigan Unit 40 Advanced Programming 13


The diagram that describes the concept for the object given above is based on a class called
Dog. That is, the diagram shows that the Dog class has the properties of Breed, age, color as
well as the methods of Bark, Sleep, Eat. In this context, the constructor of a class is important
for creating an object for a class. In this regard, the diagram above illustrates how objects such
as Dog 1, Dog 2, Dog 3, Dog 4 can be created for the Dog class using the constructor of the
dog class. Therefore, according to the data provided within the constructor used to create the
Dog 1, Dog 2, Dog 3, Dog 4 objects of the Dog class, the Dog class will be able to function
based each object as Dog 1, Dog 2, Dog 3, Dog 4. The following is an example of a real-world
example of an object like shown above:

Figure 6 Example for Object in code wise

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.

K. Sathurcigan Unit 40 Advanced Programming 14


Figure 7 Message Passing

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.

Figure 8 Example for Message Passing between the classes

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;

Figure 9 Example for Constructor

K. Sathurcigan Unit 40 Advanced Programming 15


In the Constructor creation for the above customer class, the code snippet illustrates how the
parameters assigned to the function are stored in the properties of the class. Therefore, the
constructor of the customer class is used during object creation for the customer class in
Car_reservation. So, the parameters that are given to the constructor are transferred from the
car_reservation class to the customer class, which is called message passing. That is, based on
the codes provided here, the data from the car_reservation class to customer class as _id = 1,
_name = sathu, _address = Kokkuvil, _contact_no = 0776823113, _NIC = 9901231231V by
their parameters for the constructor used to create the cus_obj which is the object for the
particular customer class Will be abducted. Likewise, when objects are created, message
passing is the transfer of data from one class to another.

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,

Figure 11 Diagram for Encapsulation

K. Sathurcigan Unit 40 Advanced Programming 16


On the above diagram for the Customer class, the ‘-’ is representing the private access modifier
which is used for prevent accessibility of the specific variable (properties) in other classes. As
far as this class is concerned, all the properties are private and all the methods are public. When
look at the diagram for the above customer class, can see that the properties (variables) of that
class are "private" and the methods are "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 diagram for the customer class above). This is the basic feature of
the encapsulation method. The codes of the customer class generated on this basis are as
follows:

Figure 12 Example for Encapsulation

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.

K. Sathurcigan Unit 40 Advanced Programming 17


Because classes are created by encapsulation, the methods of a class depend on the properties
of that class. Thus, when the data collected in the properties is affected, the class methods are
likely to fail. Because encapsulation keeps properties "private", access to those properties is
restricted within the class. This is why all the properties of the above class are created as
"Private" and methods as "Public" as already shown in the class diagram.

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.

Figure 13 Example for Inheritance

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.

As follows a diagram showing the interactions between these classes,

Figure 14 Diagram for Inheritance

K. Sathurcigan Unit 40 Advanced Programming 18


The diagram above shows the 3 vehicle types in their Inheritance relationship with their
common (parent class) class. Taking the above diagram, the classes called Bus, Car, Van have
the common properties of id and vehicle_type. At the same time, since these are seen as almost
identical entities, this is necessary to create a parent class that includes the common features of
the respective classes. Accordingly, the parent class of the respective classes has been created
to include the common features of the respective classes under the name vehicle. So far, the
classes have access to the properties and methods of the parent class by having an inheritance
relationship with their parent class (Vehicle class). Based on this, the coding for the 4 classes
included in the diagram above are as follows.

Figure 15 Example for Inheritance

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.

K. Sathurcigan Unit 40 Advanced Programming 19


VI. Polymorphism
The object can be taking more than one form based on the phenomena. And the program will
decide the meaning or usage for the specific actions of the object. By using this technique, the
code can be avoid copied more often.

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.

Figure 17 Diagram for Polymorphism

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.

K. Sathurcigan Unit 40 Advanced Programming 20


Figure 18 Example for Polymorphism

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.

K. Sathurcigan Unit 40 Advanced Programming 21


VII. Aggregation/composition

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.

Figure 21 Real world Example for Association

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.

K. Sathurcigan Unit 40 Advanced Programming 22


Figure 22 Diagram for Association Relationship

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.

Figure 23 Code for Association Relationship

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.

K. Sathurcigan Unit 40 Advanced Programming 23


When creating a system in a similar way the Aggregation relationship between classes is
established as shown in the following diagram.

Figure 24 Diagram for Aggregation 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,

Figure 25 Code for Aggregation Relationship

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.

K. Sathurcigan Unit 40 Advanced Programming 24


3. Composition
A special form of aggregation is composition. In the composition, if the parent object is
destroyed, the child object is also destroyed together. In this context the composition is
sometimes referred to as the “death” relationship. But really that is a strong type of aggregation.

When creating a system in a similar way the Composition relationship between classes is
established as shown in the following diagram.

Figure 26 Diagram for Composition Relationship

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,

Figure 27 Code for Composition Relationship

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.

K. Sathurcigan Unit 40 Advanced Programming 25


Activity 02
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.

2.1 Overall Scenario of the System


Family Dental Care (FDC) is a renowned Kandy-based upmarket dental practice. This offers a
wide range of dental services to customers, including Extractions, Nerve Fillings, Maxillofacial
procedures (jaw bone surgery), and Complex Dental Implants. The FDC, which provides such
services, expects a system to systematically manage its operations. The system must be able to
manage all of the following activities of the company.

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.

• Doctors, in particular, must mention the name of their postgraduate qualification as


well as the nation of the university that provided it if they are consultants. If ordinary
dentists, the number of years of experience should be indicated.

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.

K. Sathurcigan Unit 40 Advanced Programming 26


• Scanning Machines: One of the dentists at the FDC facility operates the dental scan
equipment. The management will usually assign a dentist to the machine at regular
times (i.e., 5pm to 6pm) without making an appointment. When that time window is
up, a new doctor will be assigned for free.

• Payments: Registration payment should be made at the time of registration of FDC


patients and Treatment Payment should be made at the time of treatment.

• 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.

K. Sathurcigan Unit 40 Advanced Programming 27


2.1.1 UML Class Diagram for the Scenario

Figure 28 UML Class Diagram

K. Sathurcigan Unit 40 Advanced Programming 28


The UML Diagram shown above seen as a blueprint for the FDC's required system for
managing all their activities and their assets, as described in Section called 2.1 Overall
Scenario of the System.

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.

2.1.1.1 Association Relationship Evaluation


Can observe the Association Relationship between the classes found in the UML Diagram for
a particular system designed to create a system that meets the requirements of the FDC. In
addition, the Association Relationship may play a role in maintaining communication between
classes. That is, can simply said, the UML diagram have been created by the Association
Relationship itself. Below is an example of a class with Association Relationship in the UML
Diagram above.

Figure 29 Association Relationship Example

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.

K. Sathurcigan Unit 40 Advanced Programming 29


2.1.1.2 Inheritance Relationship Evaluation
Inheritance Relationship is a connection method used to highlight the relationship between
parent and child classes. Approximately 5 main classes are involved in such a parent-child
relationship in the UML Diagram for the system to meet the requirements of the FDC.
Meanwhile the relationship between these is shown by Inheritance Relationship. Among them,
the following is an example of an Inheritance Relationship that deals with a parent class and
its children classes relationships:

Figure 30 Inheritance Relationship Example

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.

2.1.1.3 Aggregation Relationship Evaluation


Aggregation Relationship is a type of relationship used to highlight the relationship between
classes. The difference of the relationship method is that the two classes in the relationship can
be created separately without one. Thus, the following is an example for the Aggregation
Relationship:

K. Sathurcigan Unit 40 Advanced Programming 30


Figure 31 Aggregation Relationship Example

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.

2.1.1.4 Composition Relationship Evaluation


Composition Relationship is the exact opposite of Aggregation Relationship. That is, which
classes were in the Composition Relationship, cannot be standalone without one of the classes.
An example of this is as follows:

Figure 32 Composition Relationship Example

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.

K. Sathurcigan Unit 40 Advanced Programming 31


2.2 Build an Application derived from UML Class Diagrams.
The management system for the FDC was developed as follows, based on the created UML
diagram according to the scenario provided.

2.2.1 Classes Created based on Inheritance


I. Employee Class

Figure 33 Part of the Employee class-based UML diagram

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:

Figure 34 Employee Class

K. Sathurcigan Unit 40 Advanced Programming 32


The code snippet above shows how the Employee class and other related child classes are coded
for work together using the keywords "abstract" and "extends". Can also see that the parent
class includes common properties and methods for children classes. Based on the scenario
provided, there are 4 types of Employees working in FDC. Thus, the above class diagram and
its codes were made. Other classes created in the same way are as follows:

II. Doctor Class

Figure 35 Part of the Doctor class-based UML diagram

Figure 36 Doctor Class

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.

K. Sathurcigan Unit 40 Advanced Programming 33


III. Payment Class

Figure 37 Part of the Payment class-based UML diagram

Figure 38 Payment Class

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.

K. Sathurcigan Unit 40 Advanced Programming 34


IV. Room Class

Figure 39 Part of the Room class-based UML diagram

Figure 40 Room Class

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

Figure 41 Part of the Treatment class-based UML diagram

K. Sathurcigan Unit 40 Advanced Programming 35


Figure 42 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.

2.2.2 Classes Created based on Aggregation


I. Room Class

Figure 43 Part of the Room class-based UML diagram

K. Sathurcigan Unit 40 Advanced Programming 36


Figure 44 Room Class

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.

2.2.3 Classes Created based on Composition


I. Appointment Class

Figure 45 Part of the Appointment class-based UML diagram

Figure 46 Appointment Class

K. Sathurcigan Unit 40 Advanced Programming 37


In a given scenario, the patient, the doctor, and the treatment are considered essential for an
appointment to occur. That is, an appointment cannot be made without the above items being
created. This is why the other 3 classes associated with it, including appointment, are found in
the Composition relationship. Therefore, the 3 classes are in as objects and also the properties
of the appointment class respectively, which means that operations in the appointment class
cannot be carried out without the creation of 3 objects. The codes for this are shown in the
image above.

II. Registration Payment Class

Figure 47 Part of the Registration Payment class-based UML diagram

Figure 48 Registration Payment Class

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.

K. Sathurcigan Unit 40 Advanced Programming 38


Activity 03
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.

3.1 Discussion about range of Design Patterns with relevant examples of


Creational, Structural and Behavioral Pattern types.
3.1.1 Design Patterns
Design patterns refer to the best practices used by experienced object-oriented software
developers. Solutions to common problems faced by software developers during software
development Design methods. These solutions have been obtained by trial and error by many
software developers over a considerable period of time. (Tutorialspoint, 2021)

3.1.1.1 Usages of Design Patterns


The Design Pattern have two main usages in Software development.

• 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.

K. Sathurcigan Unit 40 Advanced Programming 39


3.1.1.2 Types of Design Patterns
There are 3 common types of design patterns. They are as follows,
• Creational Design Patterns
• Structural Design Patterns
• Behavioral Design Patterns

1. Creational Design Patterns


Creational design patterns are mainly concern about the way of creating objects. when take a
decision at the time of instantiation of a class (i.e., creating an object of a class), these design
patterns are used.

Table 1 Creational Design Patterns


Factory Method Pattern
A factory method or factory method defines the interface or abstract class for creating
an object, but let the subclasses determine which class should be instantiated. That is,
subclasses are responsible for creating the class event.

Advantage of Factory Design Pattern


1 • The Factory Method Pattern allows subclasses to determine the object's type when
creating objects.
• This promotes loose-coupling by eliminating the need to bind application-specific
classes to the code. This means that the code only interacts with the resulting
interface or abstract class, so that will work with any class that executes that interface
or extends that abstract class.

Abstract Factory Pattern


For creating families of related (or dependent) objects, without specifying their concrete
sub-classes the Abstract Factory Pattern defines an interface or abstract class. I.e.,
Abstract Factory leases a class returns a factory of classes. Based on this, Abstract
2
Factory Pattern is one level higher than the Factory Pattern.

K. Sathurcigan Unit 40 Advanced Programming 40


Advantage of Abstract Factory Pattern
• Abstract Factory Pattern isolates the client code from concrete (implementation)
classes.
• This makes easy the exchanging of object families.
• This promotes consistency among objects.

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.

There are two types of Singleton Design Pattern


3 • Early Instantiation: creation of instance at load time.
• Lazy Instantiation: creation of instance when required.

Advantage of Singleton Design Pattern


• The object won’t be created for each request, according to this the memory will be
saved. The one and only instance will be used repeatedly.

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.

K. Sathurcigan Unit 40 Advanced Programming 41


Builder Pattern
The Builder Pattern refers an approach i.e., about construct a complex object from
simple objects using step-by-step. This is mostly used when object can't be created in
single step like in the de-serialization of a complex object.

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.

Object Pool Pattern


Basically, an object pool is a container containing a certain number of objects. When an
object is taken out of the pool, that’s not available in the pool until put again into the
pool. The objects in the pond have a life cycle: creation, verification and destruction.

Advantage of Object Pool design pattern


6
• This significantly increases the efficiency of the application.
• This can be very useful in situations where the rate for initializing a class instance is
high.
• This manages links and provides a way to reuse and share them.
• This can also provide a limit for the maximum number of objects that can be created.

(Javatpoint, 2021)

2. Structural Design Patterns


Structural design patterns define how classes and objects can be created, create larger
structures, and facilitate the structure by identifying relationships. How classes get to each
other, how they are created from other classes, these kinds of things are focused on in this way.

K. Sathurcigan Unit 40 Advanced Programming 42


Table 2 Types of Structural Design Patterns
Adapter Pattern
Adapter Pattern Focus the interface of the class, for converted the interface to another
interface that a client wants. I.e., provide the interface according to client requirement
while using the services of a class with a different interface.
1
Advantage of Adapter Pattern
• This allows two or more objects to interact that were previously incompatible.
• This allows the existing function to be reused.

Bridge Pattern
Simply "decouple the functional abstraction from the implementation such that the two
can vary independently," according to the Bridge Pattern.

2 Advantage of Bridge Pattern


• This allows the implementation and the user interface to be separated.
• This increases the extensibility of the system.
• This allows the client to be unaware of implementation specifics.

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.

3 Advantage of Composite Pattern


• This establishes class hierarchies that include both simple and complicated items.
• This facilitates the addition of new types of components.
• This gives structural flexibility with a manageable class or interface.

K. Sathurcigan Unit 40 Advanced Programming 43


Decorator Pattern
"Add a flexible extra responsibility to an object dynamically," according to the
Decorator Pattern. To put that another way, The Decorator Pattern extends the
functionality of an object at runtime through composition rather than inheritance.
Wrapper is another name for the Decorator Pattern.

4 Advantage of Decorator Pattern


• This gives more options than static inheritance.
• Because modifications are done by writing new classes, the object's extensibility is
increased.
• This makes coding easier by allowing you to create a sequence of functionality from
certain classes rather than having to code all of the action into the object.

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

Advantage of Facade Pattern


• This protects customers from the sub-system components' intricacies.
• This encourages subsystems and clients to be loosely coupled.

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.

6 Advantage of Flyweight Pattern


• The number of things is reduced.
• If the items are persistent, the quantity of memory and storage devices required is
reduced.

K. Sathurcigan Unit 40 Advanced Programming 44


Proxy Pattern
Simply said, a proxy is an object that acts as a proxy for another object. A Proxy Pattern,
according to GoF, "provides control for accessing the original object." As a result, we
may execute a variety of activities such as concealing the original object's information,
on-demand loading, and so on. Surrogate or Placeholder is another name for the proxy
7
pattern.

Advantage of Proxy Pattern


• The original thing is protected from the outer world by this.

(Javatpoint, 2021)

3. Behavioral Design Patterns


Chain of Responsibility Pattern
Sender transmits a request to a chain of objects in chain of responsibility. Any item in
the chain can handle the request. "Avoid tying the sender of a request to its recipient by
providing different objects a chance to handle the request," according to the Chain of
Responsibility Pattern. In the process of dispensing money, an ATM, for example,
employs the Chain of Responsibility design pattern. To put that another way, each
receiver generally contains a reference to another receiver. If one object is unable to
1 process the request, that is sent to the next recipient, and so on.

Advantage of Chain of Responsibility Pattern


• This decrease coupling.
• While assigning duties to objects, this offers flexibility.
• This lets a group of classes to function as if they were one; events generated by one
class may be passed to other handler classes via composition.

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.

K. Sathurcigan Unit 40 Advanced Programming 45


Advantage of Command Pattern
• This distinguishes between the object that executes the action and the object that
invokes that.
• Because existing classes aren't modified, it's simple to add new commands.

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.

Advantage of Interpreter Pattern


• This is less difficult to modify and expand the grammar.
• It's simple to put the grammar into practice.

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

Advantage of Iterator Pattern


• This allows to traverse a collection in different ways.
• This streamlines the collection's user interface.

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.

K. Sathurcigan Unit 40 Advanced Programming 46


So, what happens next? As additional classes are added, the code continues to
communicate, but it becomes increasingly harder to maintain. The mediator pattern is
intended to simplify communication across various objects or classes. This pattern
creates a mediator class that generally handles all communication between distinct
classes while also promoting code maintainability through loose coupling.

Advantage of Mediator Pattern


• The number of classes is decoupled.
• This makes object protocols easier to understand.
• Control is centralized.
• Because they don't have to communicate with one another, the individual
components become significantly simpler and easier to manage.
• Because the components do not need to have logic to communicate with one
another, they are more general.

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.

Advantage of Memento Pattern


• This keeps encapsulation borders intact.
• This makes the creator's job easier.

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.

K. Sathurcigan Unit 40 Advanced Programming 47


Advantage of Observer Pattern
• This explains the interaction between the observer and the objects.
• This allows for broadcast-style communication to be supported.

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

Advantage of State Pattern


• The state-specific behavior is preserved.
• Any state transitions are made explicit.

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.

Advantage of Strategy Pattern


9
• This acts as a stand-in for subclassing.
• Each behavior is defined within its own class, removing the need for conditional
expressions.
• This makes that easy to add new functionality without having to rewrite the
program.

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)

K. Sathurcigan Unit 40 Advanced Programming 48


3.2 Relationship between OOP and Design Patterns
All subcategories of Design Patterns are as follows:

Figure 49 Types of Design Patterns

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.

3.2.1 Singleton Design Pattern


The singleton pattern is one of Java's most basic design patterns. This style of design is under
the creative category since that is one of the most effective methods to construct an object. As
this can see in the figure above.

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)

So, if consider at the code for the Design Pattern,

K. Sathurcigan Unit 40 Advanced Programming 49


Figure 50 Code for Singleton Design Pattern

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 51 Outside from the Class

K. Sathurcigan Unit 40 Advanced Programming 50


The code snippet above shows the same object created in a particular class being used by calling
the getInstance() static method created to return the created object within the "singleObject"
class. Thus, the object is created here using the code [SingleObject object =
SingleObject.getInstance();] and using the static method called getInstance() on the class
SingleObject. Therefore, the methods in the SingleObject class are used through objects here.

Figure 52 Output
The image above shows how Hello World is printed as code in the showMessage () method in
the SingleObject class.

How the Design Pattern relate with OOP concepts


• Can see in the image above, the instance is the property of the class, which is in "Private"
and the class methods showMessage() and getInstance() methods are "Public". Such a
process is seen as adopting a method called Encapsulation of the OOP concept. Thus, can
see that the design patterns are simply and systematically coded using the OOP concept.

• 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.

3.2.2 Composite Design Pattern


When need to handle a set of items as if they were a single object, can utilize the composite
pattern. The composite pattern assembles things into a tree structure to represent both parts and
the entire hierarchy. This design pattern is classified as a structural pattern since that generates
a tree structure for a set of things. (Tutorialspoint.com, 2021)

K. Sathurcigan Unit 40 Advanced Programming 51


This pattern generates a class with a collection of its own objects. This class allows to change
the properties of a set of similar objects. So, if consider at the code for the Design Pattern,

Figure 53 Example for Composite 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.

K. Sathurcigan Unit 40 Advanced Programming 52


Figure 54 Application class for Composite design pattern

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.

How the Design Pattern relate with OOP concepts


• The OOP concept called Encapsulation method has been used in the Composite design
pattern.
• The object is used in the code made using the Composite design pattern, which is another
OOP concept.
• In this case, I was able to observe the message passing when calling the function from one
class to another's. This is another OOP concept.

K. Sathurcigan Unit 40 Advanced Programming 53


3.2.3 Observer Design Pattern
When there is a one-to-many relationship between items, such as when one object is updated,
its dependent objects must be alerted automatically, the observer pattern is employed. Observer
pattern is a type of behavioral pattern. (Tutorialspoint.com, 2021)

Structure:

Figure 55 Diagram for Observer Design Pattern

Figure 56 Observer Class

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.

K. Sathurcigan Unit 40 Advanced Programming 54


Figure 57 Children classes of Observer 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.

How the Design Pattern relate with OOP concepts


• Can see that the OOP concept called Inheritance is used in the Observer Design Pattern.
• Can see that the function of the parent class is overridden in the children class, which is a
feature based on the OOP concept called Polymorphism.

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.

K. Sathurcigan Unit 40 Advanced Programming 55


Activity 04
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).
4.1.1 Scenario 01
The FDC features the most expensive, sophisticated tooth scan machine (superior to the
traditional dental X-ray machine) made by Toshiba of Japan. In the future the FDC will only
own one such machine. When modeling and implementing the FDC system in software, need
to make sure that only one instance of that machine is generated. Suitable attributes for the
machine can be added such as serial number, product, country of birth and price. Activation
should allow the user to enter the details of the tooth scanner and create a single instance of
that machine.

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:

Figure 58 Diagram for Singleton Design Pattern

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.

K. Sathurcigan Unit 40 Advanced Programming 56


Following is the class diagram created for Scan_Machine class based on this Singleton Design
Pattern concept.

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

Figure 60 Diagram for Scan Machine Class

K. Sathurcigan Unit 40 Advanced Programming 57


Figure 61 Code for the Scan Machine Class

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.

Figure 62 Evidence for prevention of object creation

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.

K. Sathurcigan Unit 40 Advanced Programming 58


Figure 63 Confirmation for single object has been used for Scan Machine Class

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.

K. Sathurcigan Unit 40 Advanced Programming 59


4.2.2 Scenario 02
Create a system to display the details of all the employees shown in the table below and the
system should clearly show which employee is working under which employee.

Table 3 hierarchy of the Employees and their monthly salary in FDC


Emp Id Name Position Salary
A001 Anton Director 1,000,000 LKR
A002 Chamod Dentist 600,000 LKR
A003 Supuni Dentist 600,000 LKR
A004 Madhavi Dentist 600,000 LKR
A005 Piyal Nurse 200,000 LKR
A006 Kamal Nurse 200,000 LKR
A007 Kapila Nurse 200,000 LKR

Note: working under the Dentists and Chamod (Dentist) is working under the Supuni (Dentist)
and Madhavi (Dentist) is working under the Anton (Director).

Figure 64 Class diagram for Employee

K. Sathurcigan Unit 40 Advanced Programming 60


4.2.2.1 Selected Design Pattern for the Scenario and Reason for that.
According to Scenario 02, the Composite Pattern has been determined to be optimal for
creating an employee class that systematically visualizes employees according to their status
and what employees they work under.

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 65 Diagram for Composite Design Pattern

• When an application has a hierarchical structure and requires generic functionality


throughout the hierarchy.
• When an application must combine data from several sources across a hierarchical
structure.
• When a program wishes to handle composite and individual items the same way.

K. Sathurcigan Unit 40 Advanced Programming 61


The composite pattern is used to create classes with the following types of structure
connections.

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.

Figure 67 Property Creation for the Class

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.

K. Sathurcigan Unit 40 Advanced Programming 62


Figure 68 Methods of the 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.

Figure 69 Function for Print the Employees

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.

K. Sathurcigan Unit 40 Advanced Programming 63


Figure 70 The Given Data insertion

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.

Figure 71 Output for the Implementation

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.

K. Sathurcigan Unit 40 Advanced Programming 64


Figure 72 Tree Structure for the given Scenario

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.

4.2.3.1 Queue Operations


I. Queue
Queue is a linear list. Data can only be added into Queue at one end of the back. When data is
removed from Queue, which is removed from the front. So here First In First Out (FIFO)
method is used. Because the front node on Queue contains the first inserted data. Therefore,
according to the Queue Condition, when data is deleted from Queue, it must be removed from
the front.

The basic operations of the Queue.


• Queue operation: Create an empty Queue.
• Enqueue operation: Insert data into the Queue at rear.
• Dequeue operation: Delete the data from front position of the Queue.
• Empty operation: Checking if the Stack is empty.

K. Sathurcigan Unit 40 Advanced Programming 65


These operations of the Queue are explained through the picture below.

Figure 73 Basic operations of the QUEUE

Situations where the Stack method is used.


• Queues are utilized in online business applications, for, processing customer requests,
occupations and orders.

II. Major Operation of the Queue


Table 4 Operation of the Queue

Functions Their Functionalities

No parameters are required to execute this function and thereby create a


Queue()
new queue that is empty.

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)

K. Sathurcigan Unit 40 Advanced Programming 66


4.2.3.2 System Implementation According to the Scenario 03
In the case of Scenario 03, patients who receive an appointment for treatment in that system
should be displayed by the system in the same order in which they receive the Appointment,
i.e., Queue method. The codes for patient class accordingly created are as follows,

Figure 74 Property Creation for the Class

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.

Figure 75 Code for Insert & View Patients

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.

K. Sathurcigan Unit 40 Advanced Programming 67


Figure 76 Created List for store the Patients Details

The Patient class is based on the following class diagram.

Figure 77 Diagram for the Patients class

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:

Figure 78 search() Method

K. Sathurcigan Unit 40 Advanced Programming 68


The code snippet above shows how the required patient data is extracted from the patient_list
by the function. Normally when inserting data into a list and extracting data from a list it works
according to the queue method. Thus not only the patient insert, update, delete functions
performed by the above patient class, but also the showAll() (display()), search() functions
mentioned in scenario 03 are performed according to the queue method of First in First Out.
The following figure illustrates how the insert(), display() and search() methods work
according to the queue method.

Figure 79 Queue operation based on Scenario 03

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.

K. Sathurcigan Unit 40 Advanced Programming 69


Structure:

Figure 80 Diagram for Iterator Design Pattern

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.

K. Sathurcigan Unit 40 Advanced Programming 70


Conclusion
This assignment was written in accordance with the situation provided. This provided
experience similar to that of working in a software firm. Because only there do employees
operate under the direction of a team leader or the corporation.

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.

K. Sathurcigan Unit 40 Advanced Programming 71


Self-Criticism
According to this assignment can able to understand what the programming is. And also, can
get more knowledge through developing a system. Because when running an application, some
errors will show at the time, through solve those errors, can understand the programming
deeply.

Benefits of the developing system


• Can get more IT related ideas through this.

• Can understand how to write code in proper manner (organized) through the experience
of solving errors.

• Can get experiences with programming languages.

• I have learned about how to debug the error in console application.

• 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.

K. Sathurcigan Unit 40 Advanced Programming 72


Gantt Chart
Table 5 Gantt Chart

K. Sathurcigan Unit 40 Advanced Programming 73


References

Javatpoint, 2021. Design Patterns in Java. [Online]


Available at: https://www.javatpoint.com/design-patterns-in-java
[Accessed 25 July 2021].

Runestone academy, 2021. [Online]


Available at:
https://runestone.academy/runestone/books/published/pythonds/BasicDS/TheQueueAbstract
DataType.html
[Accessed 17 August 2021].

Terms, T., 2021. Object. [Online]


Available at: https://techterms.com/definition/object
[Accessed 14 June 2021].

Tutorialspoint.com, 2021. Design Pattern - Singleton Pattern. [Online]


Available at: https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm
[Accessed 1 Aug 2021].

Tutorialspoint, 2021. Design Pattern - Overview. [Online]


Available at: https://www.tutorialspoint.com/design_pattern/design_pattern_overview.htm
[Accessed 25 July 2021].

K. Sathurcigan Unit 40 Advanced Programming 74

You might also like