Professional Documents
Culture Documents
Higher Nationals
Internal verification of assessment decisions – BTEC (RQF)
Assignment title
R.M. Dulith Sanjana Ramanayake
Student’s name
List which assessment Pass Merit Distinction
criteria the Assessor has
awarded.
INTERNAL VERIFIER CHECKLIST
Y/N
Does the assessment decision need
Y/N
amending?
Assessor signature Date
Confirm action
completed
Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
Unit Title
Assignment Number Assessor
Date Received 1st
Submission Date submission
Date Received 2nd
Re-submission Date submission
Assessor Feedback:
LO1. Examine the key components related to the object orientated programming paradigm,
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and grades decisions have
been agreed at the assessment board.
Assignment Feedback
Formative Feedback: Assessor to Student
Action Plan
Summative feedback
Assessor Date
signature
Student Date
signature
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.
1. The font size should be 12 point, and should be in the style of Time New Roman.
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.
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
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.
3. I know what the consequences will be if I plagiarise or copy another’s work in any of the
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.
Unit Tutor
Assignment Title
Issue Date
Submission 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.
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.
BOC Software solutions is leading software company in Kandy as system analyst you have to build
an application for Family Dental Care (FDC) considering given scenario.
Family Dental Care (FDC) is a leading up market dental surgery located in Kandy. It provides
all types of dental treatments to patients which include extractions, nerve fillings, maxillofacial
surgeries (i.e. surgeries involving jaw bone) and sophisticated dental implants. It is visited by
prominent dentists and dental consultants with post graduate qualifications, some of whom are
working at the Faculty of Dental Science at the University of Peradeniya.
Patients consult doctors by appointment. On their first visit, patients are required to register by
entering their personal details such as name, address, national identity card number and contact
number. A small fee is charged from the patient during registration. A separate fee is charged for
each treatment given.
Doctors too must get registered at FDC by providing personal details such as name, address, date
of birth, national ID number and contact number. In addition, consultants must provide the name
of their post graduate qualification along with the country of the University that granted it and
ordinary dentists should indicate the number of years of experience.
FDC consists of four fully equipped surgery rooms so that four patients can be accommodated at
any given time. FDC also contains a dental scan room which can be attended by one patient at a
time. The dental scan machine is operated by one of the dentists of the FDC facility. Normally, a
dentist without appointments for a given time slot (say, between 5 PM and 6 PM) is assigned to
the machine by the manager. When that time slot finishes, another doctor who is free will be
assigned.
The staff of FDC is made up of a manager, four nurses (one for each of the four surgery rooms)
and a receptionist who handles registrations and appointments.
An information system is required to keep track of patients, doctors, appointments, treatments
given to patients and payments. The system must also maintain information about the staff. It
has been decided to use an object oriented approach to design and implement the system.
Task 1
Examine the Object oriented concepts given below. Provide diagrams and code snippets from
suitable specific programming language to supplement your explanations.
i) Class
ii) Object
iii) Message
iv) Encapsulation
v) Inheritance
vi) Polymorphism
vii) Aggregation/composition
Task 2
Design and build the detailed UML class diagram for the Family Dental Care system. Your
solution should demonstrate all inter-class relationships namely Association, Inheritance and
Aggregation/composition. The classes should include attributes and methods needed.
Draw the class diagram for the explained system. Including all notations and details and ensure that
the diagram has the required functionalities. Analyze the class diagram provided above and derive
code scenarios related to the UML diagram.
Task 3
Determine and briefly discuss the range of design patterns and describe at least
one design pattern from the three available types of design pattern. Provide
suitable UML diagrams for the given patterns and analyze the relationship
between object-oriented paradigm and design patterns providing a suitable
example.
Task 4
Scenario 1
FDC owns a very expensive, state of the art dental scan machine (a device far superior to a
traditional dental X-ray machine) manufactured by Toshiba, Japan. FDC will be own just
one such machine in the foreseeable future. When modeling and implementing FDC system
in software, you must ensure that only one instance of that machine is created.
You may include suitable attributes for the machine such as serial number, make, country
of origin and cost. Implementation should allow the user to enter details of the dental
scanner and create the sole instance of that machine.
Scenario 02
Below table provides the hierarchy of the Employees and their monthly salary in FDC.
All the Nurses are working under the Dentists and Chamod(Dentist) is working under the
Supuni(Dentist) and Madhavi(Dentist) is working under the Anton(Director).
Develop a system to display the details of all employees and your system should display which employee is
working under which employee clearly.
Scenario 03
Patients who need dental scans are kept in a First in First Out queue. Assume that you
have found an already developed Queue container in a software library. It provides
standard queue operations to insert and remove data (known as enqueue and deque
respectively). However, you need some specific operations such as search() to look up a
particular patient and showAll() to list all the patients in the queue. These additional
operations are not provided by the library unit.
For each of the above scenarios:
Select and Justify the most appropriate design pattern for each of the above given scenarios then Define
and Draw class diagrams for above mentioned design patterns and develop code for the above scenarios
(except for the 3rd Scenario) using an appropriate programming language. Critically evaluate why you
selected the above design patterns and compare your answer with the range of design patterns available.
Grading Rubric
Table of Contents
Chapter 01........................................................................................................................................................24
1.1.1 Advantages of OOPS.......................................................................................................................25
1.1 Class........................................................................................................................................................25
1.1.1 Class diagram Example....................................................................................................................26
1.2 Objects....................................................................................................................................................27
1.2.1 The Difference between Object & Class..........................................................................................28
1.3 Encapsulation..........................................................................................................................................29
1.3.1 Advantages of Encapsulation...........................................................................................................30
1.4 Aggregation............................................................................................................................................32
1.4.1 Define an aggregation relationship between the Student class and the Subject class as follows:...33
1.5 Composition............................................................................................................................................34
Generalization...........................................................................................................................................34
Associative................................................................................................................................................35
1.6 Inheritance..............................................................................................................................................36
1.7 Message..................................................................................................................................................37
1.8 Polymorphism.........................................................................................................................................39
1.9 Determine a design pattern from each of the creational, structural and behavioral patterns.................40
1 Creational Patterns.................................................................................................................................41
2 Structural Patterns:................................................................................................................................42
3. Behavioral Patterns:..............................................................................................................................44
Chapter 02........................................................................................................................................................45
2.1 UML Class Diagram...............................................................................................................................45
2.1.1 Association.................................................................................................................................47
2.1.2 Generalization (Inheritance)............................................................................................................47
2.1.3 Aggregation......................................................................................................................................49
2.1.4 Composition.....................................................................................................................................49
2.2 FDC UML Class Diagram......................................................................................................................50
2.3 Implementation of FDC Class Diagram.................................................................................................52
Chapter 03........................................................................................................................................................81
3.1 Design Patterns.......................................................................................................................................81
3.1.1 Creational.........................................................................................................................................81
3.1.1 Use case of creational design pattern-.............................................................................................82
3.1.3 Benefits of Design Patterns..............................................................................................................84
3.1.3 Structure of a Design Pattern...........................................................................................................85
3.1.4 Design patterns are useful to computer programmers.....................................................................85
3.2 Singleton Design Pattern........................................................................................................................86
3.2.1 Coding Snapshot..............................................................................................................................87
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
Figures
Figure 1 OOP (Kaushik, n.d.)..........................................................................................................................25
Figure 2 Class..................................................................................................................................................27
Figure 3 Class Diagram...................................................................................................................................28
Figure 4............................................................................................................................................................28
Figure 5 Objects...............................................................................................................................................29
Figure 6 Difference between Object & Class...................................................................................................30
Figure 7 Dog object.........................................................................................................................................30
Figure 8 Encapsulation....................................................................................................................................30
Figure 9 Encapsulation (S, 2022)....................................................................................................................32
Figure 10 implement Encapsulation in Java....................................................................................................33
Figure 11 Example diagram of Composition (Sudhakaran, 2019)..................................................................35
Figure 12 Example of diagram Generalization (tutorialspoint, n.d.)..............................................................36
Figure 13 Examples diagram of Associative....................................................................................................36
Figure 14 Inheritance.......................................................................................................................................37
Figure 15 Inheritance Diagram (Parson, n.d.)................................................................................................38
Figure 16..........................................................................................................................................................38
Figure 17 Message Passing.............................................................................................................................39
Figure 18 Message Passing Diagram (panonit, n.d.)......................................................................................39
Figure 19 Polymorphism ex.............................................................................................................................41
Figure 20 Design Patterns...............................................................................................................................42
Figure 21 9creational design pattern (Tellmehow, 2019)................................................................................43
Figure 22 Structural Design Pattern (starship-knowledge, n.d.).....................................................................45
Figure 23 Behavioral design pattern (data-flair, n.d.).....................................................................................46
Figure 24 Association Class Diagram (stackoverflow, 2019)..........................................................................48
Figure 25 Generalization Class Diagram........................................................................................................49
Figure 26 Aggregation Class Diagram............................................................................................................50
Figure 27 Composition Class Diagram...........................................................................................................51
Figure 28 UML Class diagrams (diagrams.net, 2022)....................................................................................51
Figure 29 Class Diagram Explain...................................................................................................................52
Figure 30 Singleton Class Diagram (tutorialspoint, n.d.)...............................................................................87
Figure 30 Singleton Class Diagram (tutorialspoint, n.d.)...............................................................................87
Figure 31 Singleton Code ex............................................................................................................................87
Figure 31 Singleton Code ex............................................................................................................................87
Figure 32 Factory coding ex............................................................................................................................88
Figure 32 Factory coding ex............................................................................................................................88
Figure 33 Factory UML diagram (commons.wikimedia, n.d.)........................................................................91
Figure 33 Factory UML diagram (commons.wikimedia, n.d.)........................................................................91
Figure 34 Adapter UML (geeksforgeeks, 2022)...............................................................................................94
Figure 34 Adapter UML (geeksforgeeks, 2022)...............................................................................................94
Figure 35 Bridge UML (geeksforgeeks, 2021).................................................................................................95
Figure 35 Bridge UML (geeksforgeeks, 2021).................................................................................................95
Figure 36 Decorator UML (tutorialspoint, n.d.)..............................................................................................96
Figure 36 Decorator UML (tutorialspoint, n.d.)..............................................................................................96
Figure 37 Facade UML (tutorialspoint, n.d.)..................................................................................................97
Figure 37 Facade UML (tutorialspoint, n.d.)..................................................................................................97
Figure 38 Flyweight pattern UML (tutorialspoint, n.d.)..................................................................................98
Figure 38 Flyweight pattern UML (tutorialspoint, n.d.)..................................................................................98
Figure 39 Proxy Pattern (tutorialspoin, n.d.)................................................................................................104
Figure 39 Proxy Pattern (tutorialspoin, n.d.)................................................................................................104
Figure 40 Observer design pattern (tutorialspoint, n.d.)...............................................................................106
Figure 41 Observer Uml................................................................................................................................106
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
Chapter 01
The major motivating factor in the invention of object-oriented approach is to remove some of the flaws
encountered in the procedural approach. OOP treats data as a critical element in the program
development and does not allow it to flow freely around the system. It ties data more closely to the
function that operate on it and protects it from accidental modification from outside function. OOP
allows decomposition of a problem into a number of entities called objects and then builds data and
function around these objects.
1. OOP offers associates an easy-to-understand and clear standard structure for programs.
2. Objects created for Object-Oriented Programs are reused in alternative programs. therefore it saves
important development prices.
3. Massive programs square measure troublesome to jot down, however if the event and coming up
team follow the OOPS idea then they'll higher style with minimum flaws.
1.1 Class
A class may be a user-defined blueprint or paradigm from that object square measure created. It outlines the
set of properties or strategies that square measure general to all or any objects of 1 kind. In general, category
declarations will incorporate these parts, in order:
Modifiers: is public or holds the default access category keyword: class keyword is employed to
come up with a category.
Class name: The name ought to start with an associate initial letter (capitalized by convention).
Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword
extends. a category will solely elongate (subclass) one parent.
Interfaces(if any): A comma-separated list of interfaces enforced by the category, if any, preceded
by the keyword implements. a category will implement quite one interface.
Constructors square measure used for initializing new objects. Fields square measure variables that offer the
state of the category and its objects, and strategies square measure wont to implement the behavior of the
category and its objects.
Figure 2 Class
According to the java syntax once we produce a category the primary letter of the category should begin
with associate capital and therefore the name of the java file ought to match the category name.
Figure 4
1.2 Objects
It is a basic unit of Object-Oriented Programming and depicts real-life entities. A typical Java program
generates several objects, that as you recognize, communicate by invoking strategies. associate object
consists of
State: it's delineated by attributes of the associate object. It conjointly reveals the properties of the
associate object.
Behavior: it's pictured by the strategies of the associate objects. It conjointly reflects the response of
associate objects to alternative objects.
Identity: It offers a singular name to associate objects and permits one object to act with alternative
objects
Figure 5 Objects
A category may be a blueprint or paradigm that defines the variables and therefore the strategies
(functions) common to all or any objects of an exact kind.
An object may be a specimen of a category. package objects square measure usually won't to model
real-world objects you discover in the standard of living.
1.3 Encapsulation
Figure 8 Encapsulation
Encapsulation is outlined because of the wrapping from information underneath one unit. it's the mechanism
that binds along code and therefore the information it manipulates. differently to deem encapsulation is, it's a
protecting protect that stops the information from being accessed by the code outside this protection.
Technically in encapsulation, the variables or information of square measure hidden from the other category
and might be accessed solely through any member operating of its class during which they're declared.
As in encapsulation, the information in a very category is hidden from alternative categories, thus it's
conjointly called information concealment. Encapsulation is achieved by declaring all the variables within
the category as non-public and writing public strategies within the category to the line and finding the values
of variables exploiting the getter-setter methodology.
2. offer public setter and getter strategies to rework and consider the values of the variables.
The main good thing about exploitation encapsulation is that the security of the information. blessings of
encapsulation include:
1. Encapsulation shields associated objects from unwanted access by purchasers.
2. Encapsulation permits access to the level while not revealing the complicated details below that
level.
3. It decreases human errors.
4. Analyzes the upkeep of the applying
a) There square measure 2 small print whereby we will reach or implement encapsulation
within the Java program.
b) Declaring the instance variable of the category as non-public. so it can not be accessed
directly by anyone from outside the category.
c) Provide the general public setter and getter strategies within the category to set/modify the
values of the variable/fields.
On on-top of the program, the category Animal is encapsulated because the variables square
measure declared non-public. The get strategies like getName(), get voice(), and getAnimalCat()
square measure set as public, these strategies square measure wont to access these variables. The
setter strategies like setName(), setVoice(), and setAnimalCat()declared as public and are wont to
set the values of the variables.
1.4 Aggregation
Aggregation in Java may be a relationship between 2 categories that are best delineated as a "has-
a" and "whole/part" relationship. it's an additional specialized version of the association
relationship. the mixture category contains a relation to another category and is claimed to own
possession of that category. every category documented is taken into account to be part of the
mixture category.
1.4.1 Define an aggregation relationship between the Student class and the Subject
class as follows:
1.5 Composition
The composition may be a special case of aggregation that's a restricted aggregation referred to as
composition. If the associate object contains another object and the contained object cannot exist while not
the existence of an instrumentation object.
It represents part-of relationship and during this, each entities square measure counting on one another.
Generalization
It is a method of exacting shared characteristics from 2 or additional categories and mixing them into a
generalized super category. Generalization is additionally referred to as a “Is A Relationship”.
Associative
One to One, several to 1, several to several, and several to 1 of these relationships square measure
associations between objects.
An aggregation may be a special sort of association and composition may be a special sort of aggregation.
1.6 Inheritance
Inheritance in Java may be a mechanism during which one object acquires all the properties and
behaviors of a parent object. it's a vital part of OOPs (Object adjusted programming systems). The
idea behind inheritance in Java is that you simply will generate new categories that square measure
designed upon enduring categories. after you inherit from the associate existing category, you'll
utilize strategies and fields of the parent category.
Moreover, you'll add new strategies and fields in your current category conjointly. Inheritance
represents the ISA relationship that is additionally called a parent-child relationship.
Figure 14 Inheritance
Figure 16
1.7 Message
Message Passing in terms of computers is communication between processes. it's a sort of communication
employed in object-oriented programming furthermore as parallel programming. Message passing in Java is
like a causation associate object i.e. message from one thread to a different thread. it's used once threads
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
don't have shared memory and square measure unable to share monitors or semaphores or the other shared
variables to speak.
1.8 Polymorphism
1. Polymorphism is the ability of associate objects to require several forms. the foremost common
use of polymorphism in OOP happens once a parent category reference is employed to check
with a toddler category object.
2. Any Java object which will pass quite one IS-A take a look at is taken into account to be
polymorphic. In Java, all Java objects square measure polymorphic since any object can pass the
IS-A take look-at for its kind and therefore the category Object.
3. It's necessary to grasp that the solely attainable thanks to access associate objects is thru a
reference variable. A reference variable is of just one kind. Once declared, the kind of reference
variable can not be modified.
4. The reference variable is reassigned to alternative objects as long as it's not declared final.
The type of the reference variable would verify the strategies that it will invoke on the item.
A reference variable will check with any object of its declared kind or any subtype of its declared
kind. A reference variable is declared as a category or interface kind (Anon., 2022)
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
Figure 19 Polymorphism ex
1.9 Determine a design pattern from each of the creational, structural and behavioral
patterns
A style pattern may be a resolution approach to a general downside, It ought to be associated with business
customary while not language-dependent package engineering, a style pattern may be a usual repeatable
resolution to a typically occurring downside in package style. A style pattern isn’t a finished style that will
be modified directly into code. it's an illustration or template for the way to unravel a drag which will be
used in many alternative things. There square measure 3 varieties of style patterns and their subtypes.
1 Creational Patterns
Creational Patterns execute and support the creation of objects. It all concerns the category of mental
representation. This pattern is partitioned into class-creation patterns and object-creational patterns. category
creational patterns use inheritance with efficiency within the mental representation method whereas object-
creation categories use delegation with efficiency to urge the task completed. a number of its patterns
include:
1. Singleton
In the Singleton pattern, solely one instance of a category is formed and enforced with international access
thereto object.
3. Builder
It Lets subclasses verify that category to instantiate and provides higher management over the development
method. It facilitates additional decipherable object creation and lets the U.S. offer the fields that square
measure expressly needed.
4. Prototype
Uses the cloning methodology to duplicate enduring instances to be used as a paradigm instance for making
new objects. This methodology is applied once the new instance is effective to form and therefore the
needed objects square measure the same as actual objects.
2 Structural Patterns:
Structural Patterns advance to define relationships between objects. Some of its patterns include:
1. Adapter
Works between 2 freelance and incompatible interfaces by reworking the interface into another interface
shopper expect.
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
2. Bridge
Represent part-whole hierarchies by composing objects into tree structures. Individual objects and therefore
the composition of objects square measure handled uniformly by the shopper in Bridge.
3. Composite
Treats a bunch of objects as one object. used in tree-like structures wherever the parent node depends on the
kid node.
4. Decorator
The Decorator pattern supports inserting practicality into the associated objects dynamically throughout the
run time.
5. Flyweight
A flyweight pattern is dead if variant objects from one category got to be made wherever the objects square
measure distributed to limit memory overload.
6. Proxy
In a Proxy pattern, the associate object may be a proxy to one thing else and might regulate it. It permits the
creation and access of something sort of a massive object in memory, file, or alternative resources.
3. Behavioral Patterns:
Behavioral patterns determine the behavior of the objects. It is involved with the communication
between objects. Some of its patterns include:
1. Chain of responsibility: This pattern illustrates the way for passing requests between a
series of objects.
2. Command: during this pattern, the associate object is employed for encapsulating each
piece of knowledge claimed for playacting associate action or triggering events within the
future.
3. Interpreter: The interpreter pattern specifies an illustration of descriptive linguistics
providing a way to include language attributes within the program.
7. State: State pattern permits the item to change the inner behavior once the state transitions.
8. Visitor: The visitor pattern enables the developer to add one or more operations in an object
during the run time.
Chapter 02
Design an in-depth UML category diagram for the Family aid system. Your answer ought to
demonstrate all 3 inter-class relationships, particularly Association, Inheritance, and
Aggregation/composition. The categories ought to embody attributes and strategies. (LO 2)
Class Diagram offers the static read of associate application. a category diagram describes the
kinds of objects within the system and also the different kinds of relationships that exist among
them. This modeling technique will run with the majority of Object-Oriented strategies. will seek
advice from another class. a category will have its objects or could inherit from alternative
categories.
UML category Diagram offers a summary of a code by displaying categories, attributes, operations,
and relationships. This Diagram includes the category name, attributes, and operation in separate
selected compartments.
Class Diagram helps construct the code for the computer code application development.
1. Category Diagram Illustrates knowledge models for even complicated info systems
2. It provides a summary of how the application is structured before finding out the
particular code. this may simply cut back the upkeep time
1. Class Name
2. Attributes
3. Operations
2.1.1 Association
This kind of relationship represents static relationships between categories A and B. For example; a
Doctor works for a Hospital
2. It ought to be named to point the role vie by the category connected at the tip of the
association path.
In this example, the connection between doctors and normal Dentists is shown may be a study.
Inheritance is a very important pillar of OOP(Object bound Programming). it's the mechanism in
java in that one category is allowed to inherit the features(fields and methods) of another category.
Important terminology:
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
Super Class: whose options are inheritable is thought of as a superclass(or a base class or a parent
class).
Sub Class: that inherits the opposite category is thought of as a subclass(or a derived class,
extended category, or kid class). The taxonomic group will add its fields and strategies in added to
the taxonomic category fields and strategies.
Reusability: Inheritance supports the conception of “reusability”, i.e. after we need to make a brand
new category and there's already a category that features a number of the code that we would like
we can derive our new category from the prevailing category. By doing this, we tend are reusing
the fields and strategies of the prevailing category.
Dentist
2.1.3 Aggregation
Aggregation may be a special sort of association that models a whole-part relationship between a
mixture and its components.
For example, a category Hospital is created of one or additional Doctors. In aggregation, the
contained categories are ne'er completely addicted to the lifecycle of the instrumentality. Here, the
Hospital category can stay though the Doctors don't seem to be on the market.
Patients Hospital
2.1.4 Composition
The composition may be a special sort of aggregation that denotes robust possession between 2
categories once one category may be a part of another category.
For example, if Hospital has composed of categories of Doctors. The Hospital might contain
several Doctors, whereas every doctor belongs to just one Hospital. So, if the Hospital isn't
functioning all the Doctors also are removed.
Room Hospital
Attributes Class
Aggregation
Composition
Generalization
Operation
Association
package Code;
System.out.println(name);
System.out.println("Address- "+address);
System.out.println("Tele- "+phone);
System.out.println();
System.out.println();
System.out.println();
Receptionist r1 = new Receptionist();
r1.createAppointment();
/* *
* @Dulithramanayake
*/
package Code;
Manager Class
/*
*
* @Dulithramanayake
*/
package Code;
manager.setEmpCat("Manager");
manager.setName("Dulith");
manager.setAge(18);
manager.setAddress("Kuliyapitiya Embawa");
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
manager.setId("88972");
manager.setContact(762755725);
manager.setNic("36502686");
manager.setSalary(115000.00);
manager.setDetails();
System.out.println("*NIC:" +manager.getNic()+"*");
/*
*
* @Dulithramanayake
*/
package Code;
double allowance;
int workhours;
return allowance;
}
nurse1.setEmpCat("Nurse");
nurse1.setName("Dulith");
nurse1.setAge(18);
nurse1.setAddress("Kuliyapitiya Embawa");
nurse1.setId("88972");
nurse1.setContact(762755725);
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
nurse1.setNic("36502686");
nurse1.setSalary(45000.00);
nurse1.setDetails();
nurse1.setAllowance(22000);
nurse1.setWorkhours(8);
room1.setActivation("Active");
room1.setNumberofBed(2);
room1.setRoomNo(1);
System.out.println("*NIC:" +nurse1.getNic()+"*");
/*
*
* @Dulithramanayake
*/
package Code;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;
import javax.swing.text.html.HTMLDocument.Iterator;
do {
System.out.println("1. Register Patient");
System.out.println("2. Create Appointment");
ch=s.nextInt();
switch (ch) {
case 1:
System. out.print("Enter Patient ID : ");
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
int id = s.nextInt();
c.add(new Patients (id, name, address, age, nic, contact)); //new object will be added to the
collection
break;
case 2:
System.out.println("_________________________________________________________");
System.out.println(c);
break;
case 3:
} while (ch!=0);
package Code;
System.out.println("----------------Patient Appointed------------------");
}
package Code;
}
public static void main (String args []) {
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
/*
*
* @Dulithramanayake
*/
package Code;
cddoc1.setNic("26502686");
cddoc1.setAddress("Kuliyapitiya Embawa ");
cddoc1.setContact(762755725);
cddoc1.setSalary(125000);
cddoc1.setRole("Consultant Dentist and Dental Scanner Operator");
System.out.println("");
System.out.println("");
System.out.println("*Doctor " +cddoc1.getName() +" Details *");
System.out.println("* Address: " +cddoc1.getAddress()+ "*");
System.out.println("* Age: " +cddoc1.getAge()+ "*");
System.out.println("* ID " +cddoc1.getNic()+ "*");
System.out.println("*Contact No: " +cddoc1.getContact()+ "*");
System.out.println("___________________________________________________________");
/*
*
* @Dulithramanayake
*/
package Code;
String experiance;
orddoc1.setName("Dulith");
orddoc1.setAge(18);
orddoc1.setNic("86502686");
orddoc1.setAddress("Kuliyapitiya Embawa ");
orddoc1.setContact(762755725);
orddoc1.setSalary(125000);
orddoc1.setRole("Consultant Dentist and Dental Scanner Operator");
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
orddoc1.setExperiance("10 Years");
System.out.println("");
System.out.println("");
System.out.println("*Doctor " +orddoc1.getName() +" Details *");
System.out.println("* Address: " +orddoc1.getAddress()+ "*");
System.out.println("* Age: " +orddoc1.getAge()+ "*");
System.out.println("* ID " +orddoc1.getNic()+ "*");
System.out.println("*Contact No: " +orddoc1.getContact()+ "*");
System.out.println("___________________________________________________________");
}
/*
*
* @Dulithramanayake
*/
package Code;
this.id=id;
this.name=name;
this.address=address;
this.age=age;
this.nic=nic;
this.contact=contact;
}
/*
*
* @Dulithramanayake
*/
package Code;
nf.printcost();
mfs.printcost();
tet.printcost();
sdit.printcost();
/*
*
* @Dulithramanayake
*/
package Code;
String status;
public Toothextractions(String s) {
status = s;
System.out.println("--------Toothextractions Treatment-------");
System.out.println();
System.out.println(status);
System.out.println("________________________________________");
}
/*
*
* @Dulithramanayake
*/
package Code;
String status;
public SDimplants(String s) {
status = s;
System.out.println("--------SDimplants Treatment-------");
System.out.println();
System.out.println(status);
System.out.println("________________________________________");
/*
*
* @Dulithramanayake
*/
package Code;
String status;
public Maxillofacialsurgeries(String s) {
status = s;
System.out.println("--------Maxillofacialsurgeries Treatment-------");
System.out.println();
System.out.println(status);
System.out.println("________________________________________");
/*
*
* @Dulithramanayake
*/
package Code;
String status;
status = s;
System.out.println("--------Nervefillings Treatment-------");
System.out.println();
System.out.println(status);
System.out.println("________________________________________");
/*
*
* @Dulithramanayake
*/
package Code;
System.out.println("____________________________________________________________");
package Code;
package Code;
/*
* Dulithramanayake
*/
package Code;
private Scanner(String name, String serialNo, String brand, String origin, double cost) {
this.name=name;
this.serialno= serialNo;
this.brand = brand;
this.origin = origin;
this.cost = cost;
}
public void setDetails() {
public static Scanner getScanner(String name, String serialno, String brand, String origin, double cost) {
if(count ==1) {
System.out.println("Dental Scanner is already created!");
return null;
}else {
Scanner ds1instance = new Scanner(name,serialno, brand,origin, cost);
count++;
return ds1instance;
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
/*
*
* @Dulithramanayake
*/
package Code;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Chapter 03
Determine and shortly discuss the variety of style patterns and describe a minimum of one
style pattern from the 3 on the market kinds of style patterns. offer appropriate UML
diagrams for the given patterns and analyze the connection between object-oriented
paradigms and style patterns by providing an appropriate example.
A style pattern provides a general reusable answer for the common issues that occur in computer
code style. The patterns usually show relationships and interactions between categories or objects.
the concept is to hurry up the event method by providing well tested, well-tried
development/design paradigm. style patterns are programming language-independent ways of
determining a typical downside. which means a style pattern represents a thought, not a selected
implementation. By victimization the planning patterns you'll be able to build your code additional
versatile, reusable, and rectifiable.
It’s not obligatory to implement style patterns during a project continuously. style patterns don't
seem to be meant for project development. style patterns are meant for common problem-solving.
Whenever there's a requirement, you have got to implement an appropriate pattern to avoid such
issues in the future. seek out that pattern to use. you only have to be compelled to attempt to
perceive the planning patterns and their functions. solely by then, you'll be ready to choose the
correct one.
Design patterns are applied to stipulate a number of the simplest practices adopted by older object-
oriented computer code developers. A style pattern orderly titles drives and explains a general style
that inscribes a continual style downside in object-oriented systems. It illustrates the matter, the
explication, once to implement the answer and its importance.
3.1.1 Creational
These style patterns all concerned the category of mental representation or object creation. These patterns
are classified into Class-creational patterns and object-creational patterns. whereas category-creation
patterns use inheritance effectively within the mental representation method, object-creation patterns use
delegation effectively to urge the work done.
Creational style patterns are the industrial plant technique, Abstract industrial plant, Builder, Singleton,
Object Pool, and paradigm.
Suppose a developer needs to make an easy DBConnection category to attach to info and desires to access
the info at multiple locations from code, typically what the developer can do is produce an associate instance
of the DBConnection category and use it for doing info operations where needed. This ends up in making
multiple affiliations from the info as every instance of the DBConnection category can have a separate
connection to the info. To upset it, we tend to produce the DBConnection category as a singleton category,
so that just one instance of DBConnection is formed and one affiliation is established. as a result we can
manage dB affiliation via one instance thus, we can manage load balance, gratuitous connections, etc.
Suppose you would like to make multiple instances of an analogous kind and need to attain loose coupling
then you'll be able to choose an industrial plant pattern. a category implementing an industrial plant style
pattern works as a bridge between multiple categories. contemplate the associate example of victimization of
multiple info servers like SQL Server and Oracle. If you're developing associate application victimization
SQL Server info because of the back side, however within the future got to modifier the info to the oracle,
you'll get to modify all of your code, thus as industrial plant style patterns maintain loose coupling and
simple implementation we must always choose the industrial plant for achieving loose coupling and creation
of comparable quite object.
3.1.1.1 Structural
These style patterns are concerned with organizing different categories and objects to make larger structures
and supply new practicality.
Structural style patterns are Adapter, Bridge, Composite, Decorator, Facade, Flyweight, non-public category
knowledge, and Proxy.
The templet pattern defines the skeleton of the associate formula in associate operation deferring some steps
to sub-classes, The templet technique lets subclasses redefine sure steps of the associate formula while not
dynamic the formula structure. say as an example in your project you would like the behavior of the module
to be extended, specified we can build the module to behave in new and other ways because of the needs of
the applying modification or to fulfill the wants of the latest applications. However, nobody is allowed to
create ASCII text file changes thereto. it means that add however can’t modify the structure in those
eventualities a developer can approach templet style patterns.
3.1.1.3 Behavioral
Behavioral patterns are concerning distinctive common communication patterns between objects and
realizing these patterns.
The templet pattern defines the skeleton of the associate formula in associate operation deferring some steps
to sub-classes, The templet technique lets subclasses redefine sure steps of the associate formula while not
dynamic the formula structure. say as an example in your project you would like the behavior of the module
to be extended, specified we can build the module to behave in new and other ways because of the needs of
the applying modification or to fulfill the wants of the latest applications. However, nobody is allowed to
create ASCII text file changes thereto. it means that add however can’t modify the structure in those
eventualities a developer can approach templet style patterns.
Design patterns have 2 major advantages. First, they supply you with a way to unravel problems associated
with computer code development by employing a well-tried answer. the answer facilitates the event of
extremely cohesive modules with minimal coupling. They isolate the variability that will exist within the
system's needs, creating the system easier to grasp and maintain. Second, style patterns build
communication between designers additionally economically. computer code professionals will forthwith
image the high-level style in their heads once they seek advice from the name of the pattern wont to solve a
selected issue once discussing system style.
Design pattern documentation is very structured. The patterns are documented from a template that identifies
the data required to grasp the computer code downside and also the answer in terms of the relationships
between the categories and objects necessary to implement the answer. there's no uniform agreement at
intervals between the planning pattern community on a way to describe a pattern templet. authors like
different designs for their pattern templates. Some authors be more communicatory and less structured,
whereas others like their pattern template to be additional precise and have high grain in structure. we'll use
the templet 1st delineated by the authors of style Patterns as an instance of a templeate
Term Describes
Pattern Name Describes the essence of the pattern in a short, but expressive, name
Motivation Provides an example of a problem and how the pattern solves that problem
Structure Set of diagrams of the classes and objects that depict the pattern
Participants Describe the classes and objects that participate in the design pattern and their
responsibilities
Collaborations Describe how the participants collaborate to carry out their responsibilities
Table 1 Structure of a Design Pattern
A style pattern may be a common style answer to a typical style downside. a group of style patterns for a
connected field or domain is termed a pattern language. Note that there also are patterns at alternative levels:
code, concurrency, design, interaction style …
In computer code engineering, a computer code style pattern may be a general reusable answer to an
ordinarily occurring downside at intervals in a given context in computer code style. it's not a finished style
that will be remodeled directly into a supply or computer code. it's an outline or template for a way to
unravel a tangle that will be utilized in many alternative things. style patterns are formalized best practices
that the computer programmer will use to unravel common issues once coming up with an associated
application or system.
Object-oriented style patterns usually show relationships and interactions between categories or objects,
while not specifying the ultimate application categories or objects that square measure concerned. Patterns
that imply changeable states could also be incompatible with purposeful programming languages, some
patterns may be rendered spare in languages that have constitutional support for resolving the matter they're
making an attempt to unravel, and object-oriented patterns don't seem to be essentially appropriate for non-
object-oriented languages.
Design patterns could also be viewed as a structured approach to programming intermediate between the
amount of a programming paradigm and a concrete algorithmic program..
In Java, the Singleton pattern will ensure that there is only one instance of a class is created in the
Java Virtual Machine. It is used to provide a global point of access to the object. In terms of
practical use, Singleton patterns are used in logging, caches, thread pools, configuration settings,
and device driver objects.
In the plant pattern, we tend to produce associate objects while not exposing the creation logic to the
shopper and talking over the newly created object employing a common interface.
Prototype Pattern says that biological research associate actual object rather than making a brand
new one that may be tailor-made as per the need. This pattern ought to be followed if the value of
generating a brand-new object is pricey and resource-intensive.
When you would like to stay the number of categories in the associate
application at a minimum.
When the shopper application has to be oblivious to object creation and
illustration.
Structural style patterns square measure regarded with however categories and objects may be
composed, to make larger structures. The structural style patterns analyze the structure by
recognizing the relationships.
An Adapter Pattern says that simply "convert the interface of a category into another interface that a
shopper requires" .In alternative words, to implement the interface in keeping with shopper necessities
whereas mistreatment of the services of a category with a distinct interface. The Adapter Pattern is
additionally recognized as Wrapper.
When an associate object needs to use an associate existent category with the associate
incompatible interface.
When you would like to create a reusable category that assists with categories that do not
have compatible interfaces.
When you would like to get a reusable category that supports categories that do not have
compatible interfaces.
Target Interface: this can be the invited interface category that may be used by the shoppers.
Adapter category: This category may be a wrapper category that implements the required target
interface and changes the particular request accessible from the Adapter class.
Adapter category: this can be the category that's used by the Adapter class to employ the present
practicality and alter them for the required use.
Client: This category can communicate with the Adapter category.
A Bridge Pattern states that simply "decouple the purposeful abstraction from the
implementation so that the 2 will diversify autonomously".The Bridge Pattern is additionally
acknowledged as a Handle or Body.
It is usually employed in those places wherever changes square measure created within the
implementation that doesn't influence the shoppers.
A Decorator Pattern states that simply "connect versatile further charges to associate object
dynamically". In alternative terms, The Decorator Pattern utilizes composition rather than inheritance to
prolong the practicality of the associate objects at runtime. The Decorator Pattern is additionally recognized
as Wrapper.
d. When you would like to transparently and dynamically append competencies to things while
not modifying alternative objects.
e. When you would like to connect responsibilities to associate objects that you simply might
want to develop within the future.
f. Elongating practicality by sub-classing isn't any longer sensible
A Facade Pattern says that simply "just implement a unified and simplified interface to a
collection of interfaces in an exceedingly scheme, thus it covers the complexities of the scheme
from the client". In alternative words, the Facade Pattern represents a higher-level interface that
creates the scheme more leisurely to use.
A Flyweight Pattern states that simply "to employ already enduring similar reasonably objects by
accumulating them and generate a brand new object once no matching object is detected".
d) When the storage price is crucial due to the number of objects. When the application
doesn't rely on object identity.
A composite pattern may be a partitioning style pattern and describes a gaggle of objects that square
measure treated constant means as one instance of the constant style of object. A composite intends to
“compose” objects into tree structures to represent part-whole hierarchies. It permits you to own a tree
structure and raise every node within the tree structure to perform a task.
As represented by God, “Compose objects into a tree structure to represent part-whole hierarchies.
Composite lets shopper treat individual objects and compositions of objects uniformly”.
When coping with Tree-structured knowledge, programmers typically ought to discriminate between a leaf
node and a branch. This makes code additional advanced, and thus, fallible. is an interface that permits
treating advanced and primitive objects uniformly.
The key thought is that you simply will manipulate one instance of the thing even as you'd manipulate a
gaggle of them. The operations you'll be able to perform on all the composite objects typically have the
smallest amount of common divisor relationships
1. Part – The part declares the interface for objects within the composition and for accessing and
managing its kid parts. It additionally implements default behavior for the interface common
to any or all categories as applicable.
2. Leaf – Leaf defines behavior for primitive objects within the composition. It represents leaf
objects within the composition.
3. Composite – Composite stores kid parts and implements child-related operations within the
part interface.
4. Shopper – The shopper manipulates the objects within the composition through the part
interface.
The shopper uses the part category interface to move with objects within the composition structure. If the
recipient may be a leaf then the request is handled directly. If the recipient may be a composite, then it
always forwards requests to its kid parts, presumably activity further operations before and when
forwarding.
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
Proxy Pattern
Simply, a proxy indicates an associate object portrayal of another object. in keeping with GoF, a Proxy
Pattern "implements the management for accessing the initial object".So, we can complete several
operations like concealment of the knowledge of the initial object, on-demand loading, etc. A proxy pattern
is additionally called a Surrogate or Placeholder.
subsequently, we can simply talk over with the proxy to employ the thing. This circumvents
duplication of the thing and thence maintains memory.
b) It may be employed in the protecting Proxy situation. It operates as an associate
authorization layer to prove whether or not the particular user has access to the relevant
content or not. for example, a proxy server that has limitations on web access within the
workplace. solely the websites and contents that square measure original are approved and
also the remaining ones are blocked.
c) It may be employed in the Remote Proxy situation. a far-off proxy may be considered
because of the stub within the RPC decision. The remote proxy implements a neighborhood
illustration of the thing that is gifted within completely different address locations. Another
example may be providing an associate interface for remote resources like net service or
REST resources.
d) It may be employed in the good Proxy situation a wise proxy provides a further layer of
security by interposing specific actions once the thing is accessed. as an example, to
envision whether or not the $64000 object is secured or not before accessing it so that no
alternative objects will modification it
Behavioral is, however, somebody acts i.e., it consists of the tasks that one executes to move in
associated surroundings. In object-oriented software package development, the behavior of various
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
objects determines the connection between them and additionally determines their ability to
perform an exact task.
The ability of associate object-oriented software package applications to accomplish a task depends
upon the interaction of assorted objects and categories. to create an economical object-oriented
software package, we must always follow some tips that describe how completely different objects
and categories send messages to every alternative to form things happen. this can be wherever
activity style Patterns inherit the image. it's a group of templates that revolve around planning the
interaction between objects and categories.
Behavioral patterns follow the principle that the objects in associate object-oriented applications
ought to be interconnected in such a way that tough secret writing may be avoided and also the user
input may be well handled. For this principle, the activity style patterns create the use of loose
coupling techniques to confirm a versatile and effective flow of data.
Loosely coupled object-oriented software package systems square measure those within which the
parts (classes and objects) square measure sapless related to one another. because of this weak
association between the parts, the thing interactions in loosely coupled systems don't seem to be as
effective as that in tightly coupled systems. But, objects in an exceedingly loosely coupled system
square measure additional independent and are reusable as any changes created in one part have the
lowest result on the existence or the performance of another part. [ CITATION Sca \l 1033 ]
The observer pattern is employed once there's a one-to-many relationship between objects if one
object is changed, its dependent object's area unit is to be notified mechanically. The observer
pattern falls underneath the behavioral pattern class.
The observer style pattern is beneficial after you Associate in Nursing interest} within the state of
an object and need to urge notified whenever there's any modification. within the observer pattern,
the thing that watches the state of another object is termed the Observer, and therefore the object
that's being watched is termed the topic.
3.9 Analyze the relationship between object-oriented paradigm and design patterns
providing a suitable example.
Design patterns define the most effective practices adopted by full-fledged object-oriented software
package developers. style patterns area unit explications of general issues that software package
developers encountered throughout software package development. These solutions were non
heritable by trial and error by varied software package developers over quite a substantial amount.
particularly for any industry-level project, wherever it's traditional to figure with dozens or maybe
many developers; the collaboration method implies that there have to be compelled to be some
standards and rules to create the code additional elegant and convertible to modifications. that's
why we've object-oriented programming (OOP) and software package framework tools. A style
pattern is somewhat corresponding to OOP, however, it goes any by examining changes as a part of
the natural development method. the planning pattern leverages some concepts from OOP, like
abstractions and interfaces, however, concentrates on the method of change.
Design patterns area unit supported sensible solutions that are with success enforced over and once more.
style patterns represent a method of transition from analysis/design to design/implementation. A style pattern
is AN abstraction from a concrete continual answer that solves a drag during a bound context
The main relationship between object-oriented paradigms {and style|and style} patterns is that if we wish to
use oop in programming for effective code we'll use design patterns. style patterns facilitate to
implementation of the characteristics of the object-oriented paradigm.
In software package development, the effectiveness and correction of code area units are vital for that
purpose we tend to use style patterns to implement the codes smartly and effectively. Patterns offer solutions
to issues in a neater manner
Design patterns area unit nothing, however {an answer|an answer} to a continual downside and therefore the
solution is strong, scalable, readable, and versatile. they'll exist for different programming paradigms too
to unravel, and object-oriented patterns don't seem to be essentially appropriate for non-object-oriented
languages.
Design patterns embody some object-oriented ideas, with object arrangements to unravel general software
package development style issues. Implementing style patterns to your style and development can enhance
your object employ and permit for easier program changes.
Reusability and extensibility area unit the centers of the planning pattern, very like different object-oriented
practices. style patterns area unit quite primary information structures like arrays, connected lists, and binary
trees. Like information structures, a style pattern name apprehends a basic plan. in contrast to information
structures, style patterns verify the behavior of teams of objects.
The C# and Java Frameworks area unit is peppered with style patterns and ideas. several of the objects you
use during a framework develop a style pattern. a standard style pattern follow is to incorporate the name of
the pattern being enforced within the name of the thing or object. If you've got used objects during a
framework that incorporated words like a proxy, adapter, iterator, visitor, and command within the name of
the thing, possibly you've got utilized a style pattern. Understanding style patterns can develop your
understanding of the assorted C++, C#, and Java libraries and frameworks.
Aside from supplying you with AN under-the-hood perception of your development tools, applying style
patterns can enhance your software package style, development, and most vital, reusability. style patterns
area unit quite simply specifications for software package style solutions. AN object-oriented approach to
software package development is the foundation for all style patterns. acquiescence the objected-oriented
style approach of style patterns is that the commencement in understanding however style patterns can
enhance your software package development.
It's tough to jot down Java or C# while not some perception of object-oriented style and development.
Understanding style patterns entails understanding basic object-oriented ideas. If you've got done
enhancements with Java, C++, or C#, you will be acquainted with the following concepts:
Decomposition is the method of dividing a drag into shorter items, in different words, divide and conquer.
Break your program into objects, everyone with distinct responsibilities. Reusability is commonly the result
of fine decomposition.
Encapsulation conceals the inner construction of AN object. Objects are units accessed through their
interface. So, for example, encapsulation concedes AN object to vary its internal behavior while not
dynamically the approaching different objects move with it.
Polymorphism provides objects with a standard base category or interfaces to be managed similarly. AN
object "A" will move with object "B" while not being wholly awake to the thing "B's" true kind.
Inheritance is the concept of prolonging the behavior of AN object. Inheritance has 2 forms: a concrete
category ANd an abstract base category or interface inheritance. other than grammar discrepancies, the
fundamental distinction between the 2 styles of inheritance is that the quantity of practicality is dead within
the base category. AN abstract category performs no practicality within the base category, whereas a
concrete category can have some practicality within the base category.
Loosely coupled objects area unit additional freelance of every different instead of subordinate to 1 another.
Loose coupling makes it additionally appears to change AN object with very little understanding of the
larger system during which the thing resides.
Utilizing the object-oriented ideas printed higher than, style patterns solve issues by implementing these
ideas in the following ways:
The design pattern philosophy emphasizes that it's additionally obvious to vary or add AN object
implementing AN interface instead of assuming all future practicality of AN object. stress is placed on the
employment of abstract base categories, instead of on inheritance from a concrete base category. For a C#,
VB.NET, or Java developer, this means interface inheritance.
Design patterns facilitate support for easier program changes and object reusability. Loosely coupled objects
area unit additional apparent to employ and alter. Keeping objects little and specialized supports loose
coupling. style patterns area unit engineered with several little specialized objects. purposeful liabilities area
unit postponed to the thing within the system serving the perform that's being utilized. Objects delegate
responsibility to smaller specialized objects. Objects differ slightly in practicality area units comprised of
smaller objects instead of implementing most of the practicality during a common base category.
In software package style, you need to typically ascertain what forms of objects you would like in
your style. Many times, the objects you would like for your answer don't seem to be attainable
within the necessities. If the specifications exhibit AN interaction that's resolved by a style pattern,
you'll implement the pattern.
A design pattern incorporates a list of common objects and a description of how the objects
interrelate. Some common programming dilemmas are outlined below, along with the design
pattern for solving the dilemma. The examples are implemented to give you an idea of the type of
problems design patterns can determine.
Chapter 04
Scenario 1
FDC owns a costly, state-of-the-art dental scan machine (a device so much superior to a standard
dental X-ray machine) factory-made by Toshiba, Japan. FDC is own only one such machine within the
predictable future. once modeling and implementing the FDC system in the software package, you
need to make sure that only 1 instance of that machine is formed. You may embody appropriate
attributes for the machine like serial variety, make, country of origin, and value. Implementation
ought to permit the user to enter details of the dental scanner and build the only real instance of that
machine.8
Figure 53 FDC
Output
In the higher situation, the learner had enforced the Singleton style pattern. The singleton is taken into
account as one in every one of the kinds that fall underneath the class of creational style pattern. As
expressed within the situation, once implementing the FDC system it's strictly needed to make one instance
of that machine. it's mandated to facilitate the user to input details of the dental scanner which includes
attributes like serial variety, make, country of origin, and cost. The situation merely corresponds to the
singleton style pattern wherever the category is outlined in such a way that only 1 instance of the category is
formed within the complete execution of a program or project.
It is used wherever solely one instance of a category is needed to manage the action throughout the
execution. A singleton category shouldn’t have innumerable instances in any case and at any value. the most
goal of the singleton category is to manage object creation, limiting the number of objects to only 1. The
singleton provides only 1 entry purpose to make the new instance of the category.
Since there's only 1 Singleton instance, any instance fields of a Singleton can happen just once per category,
similar to static fields. Singletons area unit typically helpful once we have to be compelled to manage the
resources, like information connections or sockets.
An implementation of a singleton category for the given situation ought to possess the subsequent
properties:
1. It ought to possess only 1 instance: this can be done by implementing AN instance of the
category from at intervals the category. Outer categories or subclasses ought to be restricted
to get the instance. done by creating the creator personal in java so none of the categories
can access the creator and thence cannot instantiate it.
2. The instance ought to be globally accessible: The instance of the singleton category ought
to stay globally accessible so every category will utilize it. In Java, it's performed by
creating the access intellectual of the instance public.
The Singleton may be a style Pattern for allowing only 1 instance of your category, however, common
mistakes will unknowingly permit quite one instance to be created.
Singleton's purpose is to manage object creation, limiting the amount to 1 but providing the flexibility to
make additional objects if true changes. Since there's only 1 Singleton instance, any instance fields of a
Singleton can occur just once per category, similar to static fields.
Singletons typically regulate access to resources like information connections or sockets. as an example, if
you've got a license for less than one association for your information or your JDBC driver has to bother
with multithreading, the Singleton gets positive that only 1 association is created or that only 1 thread will
access the association at a time. If you add information connections or use a JDBC driver that supports
multithreading, the Singleton will be simply changed to supply additional connections.
3. It will be lazy-loaded.
7. It implements one purpose of access to a specific instance, thus it's simple to keep up.
Scenario 2
Develop a system to show the main points of all staff and your system ought to show that a worker is
functioning beneath that worker.
4.2.1 UML
In the above scenario, the learner had enforced a composite style pattern since the Composite style
Pattern could be a style pattern that befalls within the class of structural patterns. Such patterns are
involved however categories and objects are organized to create larger structures. Composite
Pattern describes one such approach of building a category hierarchy created from categories for 2
varied styles of objects (composite and primitive). One purpose of code engineering is to manage
high cohesion between modules and therefore the difference to decrease coupling. A composite
style pattern offers a style hierarchy, within which nodes with youngsters disagree with nodes
while not youngsters. The composite style pattern lets the consumer manage individual objects and
compositions uniformly. The core factor to stay in mind is the tree structure when administering
this style pattern.
The solution lies within the composite style pattern. The pattern consists of 2 categories mainly:
1. The part - It provides a layer of abstraction for all categories within the hierarchy.
2. The Composite – The composite contains an assortment of elements that extends the part
category.
Composite style patterns describe teams of objects which will be treated within the same approach as
one instance of constant object sort. The composite pattern permits America to "compose" objects into
tree structures to represent part-whole hierarchies. this can be referred to as a “has-a” relationship
between objects.
Scenario 3
Patients UN agency would like dental scans to be unbroken in a very initial in the initial Out queue.
Assume that you simply have found associate already developed Queue instrumentation in a very code
library. It provides commonplace queue operations to insert and take away knowledge (known as
enqueue and deque respectively). However, you wish some specific operations like search() to seem up
a specific patient and showAll() to list all the patients within the queue. These further operations
aren't provided by the library unit.
For the on-top of the state of affairs, it's doable to use an associate observer pattern since The
observer pattern illustrates a one-to-many dependency between objects so that once one object
changes state, all of its dependents are notified and updated mechanically. however supported this
on top of the question, the patient's UN agency would like a tooth doctor to scan, their details are
unbroken in a very queue that is figured beneath the (first in first out) principle. It unremarkably
has 2 basic operations enqueue and dequeue. however, during this case, the FDC asks for a few
special forms of operation for specific functions like Search() to seem up a specific patient's details
and show () operations to list all the patients within the queue. To develop these specific
operations, we've to seek out the proper methodology to implement. to resolve this drawback or
challenge we can use the Java Iterator style Pattern. This style pattern provides a mechanism to get
further operations to traverse and access instrumentation objects’ contents while not exposing their
cognitive content. An associate iterator is an associate interface that belongs to a set framework. It
permits to traverse of the gathering, accesses the information component, and removes the
information parts of the gathering. it's conjointly thought of as a Universal iterator as we can apply
it to any assortment object. By exploiting the associate Iterator, we can perform each browse and
take away operation. this can be an associate improved version of Enumeration with the extra
functionalities of the remove-ability of the part. So, exploiting this style pattern we tend to build
our operation to the queue. the subsequent section explains the idea of the Iterator pattern.
The iterator pattern could be an unremarkably used style pattern in Java and .Net programming
environments. This pattern is employed to urge away to access the weather of a set object in a very serial
manner with none got to apprehend its underlying illustration.
Implementation
We're progressing to produce an associate Iterator interface that narrates the navigation methodology and an
instrumentation interface that returns the iterator. Concrete categories implementing the instrumentation
interface are going to be accountable to implement the Iterator interface and use it
IteratorPatternDemo, our demo category can use NamesRepository, a concrete category implementation to
print Names keep as a set in NamesRepository.
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
4.3.2 Iterator
An iterator is an associate interface that's utilized in place of Enumerations within the Java assortment
Framework. Moreover, associate iterator differs from the enumerations in 2 ways:
1. The iterator permits the caller to get rid of the given parts from the required assortment throughout
the iteration of the weather.
The iterator interface could be a member connected with Java Collections Framework.
Methods Description
forEachRemaining(Cons Performs the given action on each of the element umer<? super
E>action) until and unless all the elements have been processed or unless an exception is
thrown by the action.
hasNext() Returns a true value if the more number of elements are encountered during
iteration.
Next() Returns a true value if the more number of elements are encountered during iteration.
Remove() Removes the last element from the collection
Table 2 Iterator pattern Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169
4.4 Critically evaluate a range of design patterns against the range of given scenarios
with the justification of your choice.
To put it merely, a style pattern could be an approach for developing code or apps. each style pattern
describes an answer to a particular drawback or set of challenges. Given the variability of situations declared
on top, we would be ready to leverage these style patterns to assist the sight and address those difficulties.
it's troublesome to create object-oriented code, and it's even tougher to provide code that's helpful and
reusable. to provide high-quality code, we tend should determine objects, reason them at the right level of
coarseness, style category interfaces, and link them along.
Our software's design ought to be pliable enough to handle modifications and unforeseen challenges. this
means that, whereas there's no ideal code style, will develop it in such a way that it can solve the majority of
probable future issues.
When fixing a drag, wonderful creator seldom follows the initial set of instructions; instead, they devolve
into earlier accomplishments. we can see revenant patterns within the interactions between categories. once
applied to the said instances, these patterns increased the underlying notion of object-oriented systems and
created them a lot of versatile, elegant, and reusable. What exactly could be a style pattern currently that
we've outlined it? It describes communication objects and categories that are altered to fulfill a broad style
issue in a very specific context.
Object-oriented styles will solve tons of their issues with the help of design patterns.
Any object's size is subject to variation. they're capable of commutation something, as well as hardware and
code. So, however, can we decide what's an associate object? This drawback may be solved by exploitation
style patterns. enable the American state to supply some basic vocabulary associated with object-oriented
style during this context. for every action outlined by the associate object, the name, the objects needed as
arguments, and therefore the comeback worth are all declared. this can be mentioned within the operation's
signature. The interface to associate objects is the assortment of all signatures outlined by the operations of
that object. the entire set of inquiries that will be conducted on an associate object is decided by its interface.
4.4.1 Justification
In addition to exploiting style patterns to make code, it's important to know and analyze circumstances
within which specific patterns could also be utilized.
The requirement for extensibility in our code could be an important condition within which style patterns are
used. If we wish to more and more add new options or capabilities, we tend to could amendment the
prevailing code. to attain extensibility in our program, we tend may have to use style patterns just like the
industrial plant and image patterns, which permit for the dynamic generation of objects or the ever-changing
of their options. style patterns are ofttimes helpful once there are many strategies to hold out an associate
activity or attain a definite goal. we would be ready to use a range of techniques. style patterns are usually
helpful once there are many strategies to hold out an associate activity or attain a definite goal. we would be
ready to use several style patterns, as an example, to manage events or mistakes in our programs.
Gantt Chart
Gantt Chart
10/17/2022 10/22/2022 10/27/2022 11/1/2022 11/6/2022 11/11/2022 11/16/2022
References
commons.wikimedia, n.d. commons.wikimedia.org. [Online]
Available at: https://commons.wikimedia.org/wiki/File:Factory_Method_UML_class_diagram.svg
Commons.wikimedia, n.d. commons.wikimedia.org. [Online]
Available at: https://commons.wikimedia.org/wiki/File:Composite_UML_class_diagram_%28fixed%29.svg
data-flair, n.d. data-flair.training. [Online]
Available at: https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Behavioral-Design-
Patterns.png
diagrams.net, 2022. www.diagrams.ne. [Online]
Available at: https://www.diagrams.net/blog/uml-class-diagrams
geeksforgeeks, 2021. www.geeksforgeeks.org. [Online]
Available at: https://www.geeksforgeeks.org/bridge-design-pattern/
geeksforgeeks, 2022. www.geeksforgeeks.org. [Online]
Available at: https://www.geeksforgeeks.org/adapter-pattern/
geeksforgeeks, 2022. www.geeksforgeeks.org. [Online]
Available at: https://www.geeksforgeeks.org/iterator-pattern/
Kaushik, G., n.d. geetikakaushik2020.medium.com. [Online]
Available at: https://geetikakaushik2020.medium.com/what-is-object-oriented-programming-7f14c5147ee5
[Accessed 24 September 2021].
panonit, n.d. panonit.com. [Online]
Available at: https://panonit.com/blog/overview-message-passing-object-oriented-programming
Parson, D. E., n.d. www.researchgate.net. [Online]
Available at: https://www.researchgate.net/figure/UML-class-diagram-showing-inheritance-and-
association_fig1_327544987
researchgate, n.d. www.researchgate.net. [Online]
Available at: https://www.researchgate.net/figure/Class-diagram-of-iterator-pattern_fig1_3267606
Scaler, n.d. www.scaler.com. [Online]
Available at: https://www.scaler.com/topics/design-patterns/behavioral-pattern/
S, R. A., 2022. www.simplilearn.com. [Online]
Available at: https://www.simplilearn.com/tutorials/java-tutorial/java-encapsulation
stackoverflow, 2019. stackoverflow.com. [Online]
Available at: https://stackoverflow.com/questions/58295799/association-class-attributes-in-domain-model-
class-diagram
starship-knowledge, n.d. starship-knowledge.com. [Online]
Available at: https://starship-knowledge.com/software-design-patterns
Downloaded by peter hakam (hakammohamed12345@gmail.com)
lOMoARcPSD|15607169