Uploaded by K Fernando

803-1601900046139-Unit 40- Advanced Programming

advertisement
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Higher Nationals
Internal verification of assessment decisions – BTEC (RQF)
INTERNAL VERIFICATION – ASSESSMENT DECISIONS
Programme title
Assessor
HND in Computing - Application Dev / Software Eng. Pathway
Internal
Verifier
Unit 20 – Advance Programming
Unit(s)
Assignment title
A.M.Belicks
Student’s name
List which assessment criteria
the Assessor has awarded.
Pass
Merit
Distinction
INTERNAL VERIFIER CHECKLIST
Do the assessment criteria awarded match
those shown in the assignment brief?
Is the Pass/Merit/Distinction grade awarded
justified by the assessor’s comments on the
student work?
Has the work been assessed
accurately?
Y/N
Y/N
Y/N
Is the feedback to the student:
Give details:
• Constructive?
• Linked to relevant assessment criteria?
• Identifying opportunities for improved
performance?
• Agreeing actions?
Does the assessment decision need
amending?
about:blank
Y/N
Y/N
Y/N
Y/N
Y/N
Assessor signature
Date
Internal Verifier signature
Date
1/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Programme Leader signature (if required)
Date
Confirm action completed
Remedial action taken
Give details:
Assessor signature
Date
Internal Verifier
signature
Date
Programme Leader
signature (if required)
Date
A.M.Belicks
about:blank
Unit – 20 -AP
2|Page
2/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Higher Nationals - Summative
Assignment Feedback Form
Student Name/ID
A.M.Belicks/ COL/E - 008348
Unit Title
Unit 20 – Advance Programming
Assignment Number
1
Assessor
Submission Date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Assessor Feedback:
LO1 Demonstrate a range of interpersonal and transferable communication skills to a target audience
Pass, Merit & Distinction P1 P2
Descripts
M1
D1
LO2 Apply critical reasoning and thinking to a range of problem-solving scenarios
Pass, Merit & Distinction P3 P4
Descripts
M2 M3
D2
LO3 Discuss the importance and dynamics of working within a team and the impact of team working
in different environments
Pass, Merit & Distinction P5 P6
M4 D3
Descripts
LO4 Examine the need for Continuing Professional Development (CPD) and its role within the
workplace and for higher level
learning
Pass, Merit & Distinction P7 P8
Descripts
Grade:
M5 D4
Assessor Signature:
Date:
Resubmission Feedback:
Grade:
Assessor Signature:
Internal Verifier’s Comments:
Date:
Signature & Date:
A.M.Belicks
about:blank
Unit – 20 -AP
3|Page
3/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
* 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.
A.M.Belicks
about:blank
Unit – 20 -AP
4|Page
4/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Assignment Feedback
Formative Feedback: Assessor to Student
Action Plan
Summative feedback
Feedback: Student to Assessor
Assessor
signature
Date
Student
signature
Date
A.M.Belicks
about:blank
Unit – 20 -AP
5|Page
5/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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.
A.M.Belicks
about:blank
Unit – 20 -AP
6|Page
6/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Recommended for you
55
Document continues below
1447 1628760497056 Unit 6 MSCP 2021 and 22 RW
Hnd in Computing
110
475436870 Sample Programming Assignment pdf
software project proposal
210
90% (39)
esoft metro cumpus- network assignment
software project proposal
about:blank
100% (7)
Unit-01 Programming Assignment distintion pdf
software project proposal
50
100% (11)
86% (7)
7/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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:
(Provide E-mail ID)
A.M.Belicks
about:blank
Date:
(Provide Submission Date)
Unit – 20 -AP
7|Page
8/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Higher National Diploma in Business
Assignment Brief
Student Name /ID Number
Unit Number and Title
Unit 20 – Advance Programming
Academic Year
2018/192020/21
Unit Tutor
Assignment Title
Issue Date
Submission Date
IV Name & Date
Submission format
A.M.Belicks
about:blank
Unit – 20 -AP
8|Page
9/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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.
A.M.Belicks
about:blank
Unit – 20 -AP
9|Page
10/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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
A.M.Belicks
about:blank
Unit – 20 -AP
10 | P a g e
11/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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
I) 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
I)
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.
II)
Analyze the relationship between object-oriented paradigm and design patterns
providing a suitable example.
Task 4
Scenario 01
A.M.Belicks
about:blank
Unit – 20 -AP
11 | P a g e
12/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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
The treatments given to patients at FDC can be of two types: elementary and complex. An
elementary treatment is a single procedure such as a simple extraction or a dental filling
which usually requires a single visit. A complex treatment is a composition of several
elementary treatments possibly taking several visits by the patient, for example, a tooth
implant for a severely decayed tooth may require an antibiotic treatment for curing any
pus accumulation, an extraction of the affected tooth and finally a dental implant of a
Titanium tooth. The users of the system (mainly consultants and dentists) wish to handle
both of these treatments in a uniform way. For example, the message getDetails() sent to
an elementary treatment should provide details of a single procedure while the same
message given to a complex treatment would list details of each elementary treatment
that make up the complex treatment.
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:
1. Select and Justify the most appropriate design pattern for each of the above given
scenarios.
A.M.Belicks
about:blank
Unit – 20 -AP
12 | P a g e
13/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
2. Define and Draw class
diagrams for above
mentioned design patterns.
3. Develop code for the above scenarios 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? i.e. why you selected one and
not the others.
Grading Rubric
A.M.Belicks
about:blank
Unit – 20 -AP
13 | P a g e
14/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Grading Criteria
Achieve
d
Feedback
LO1 Examine the key
components related to the objectorientated 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 Define/refine class diagrams 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.
A.M.Belicks
about:blank
Unit – 20 -AP
14 | P a g e
15/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
M4 Reconcile the
most appropriate
design
pattern from a range with a series of
given scenarios.
A.M.Belicks
about:blank
Unit – 20 -AP
15 | P a g e
16/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Contents
Task 01…………………………………………………………………………. 18 - 29
Task 02…………………………………………………………………………. 30 - 31
Task 03…………………………………………………………………………. 32 - 73
Task 04…………………………………………………………………………. 73 - 84
A.M.Belicks
about:blank
Unit – 20 -AP
16 | P a g e
17/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
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
What is OOPS?
Object-oriented programming: As the name suggests, Object-Oriented Programming or OOPs
refers to languages that uses objects in programming. Object-oriented programming aims to
implement real-world entities like inheritance, hiding, polymorphism etc in programming. The
main aim of OOP is to bind together the data and the functions that operate on them so that no
other part of the code can access this data except that function.
Polymorphism
Polymorphism refers to the ability of OOPs programming languages to differentiate between
entities with the same name efficiently. This is done by Java with the help of the signature and
declaration of these entities.
For example:
A.M.Belicks
about:blank
Unit – 20 -AP
17 | P a g e
18/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Inheritance
Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in
java by which one class is allow to inherit the features(fields and methods) of another class.
Important terminology:
Super Class: The class whose features are inherited is known as superclass(or a base
class or a parent class).
 Sub Class: The class that inherits the other class is known as subclass(or a derived
class, extended class, or child class). The subclass can add its own fields and methods
in addition to the superclass fields and methods.
 Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to
create a new class and there is already a class that includes some of the code that we
want, we can derive our new class from the existing class. By doing this, we are
reusing the fields and methods of the existing class.
The keyword used for inheritance is extends.
Syntax:

class derived-class extends base-class
{
//methods and fields
}
illustrative image of the program:
A.M.Belicks
about:blank
Unit – 20 -AP
18 | P a g e
19/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
In practice, inheritance and polymorphism are used together in java to achieve fast performance
and readability of code.
Types of Inheritance in Java
Below are the different types of inheritance which is supported by Java.
1. Single Inheritance : In single inheritance, subclasses inherit the features of one
superclass. In image below, the class A serves as a base class for the derived
class B.
A.M.Belicks
about:blank
Unit – 20 -AP
19 | P a g e
20/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
2. Multilevel Inheritance: In Multilevel Inheritance, a derived class will be
inheriting a base class and as well as the derived class also act as the base class
to other class. In below image, the class A serves as a base class for the derived
class B, which in turn serves as a base class for the derived class C. In Java, a
class cannot directly access the grandparent’s members.
3. Hierarchical Inheritance: In Hierarchical Inheritance, one class serves as a
superclass (base class) for more than one sub class.In below image, the class A
serves as a base class for the derived class B,C and D.
4.
A.M.Belicks
about:blank
Unit – 20 -AP
20 | P a g e
21/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
4. Multiple Inheritance (Through Interfaces) : In Multiple inheritance ,one class can
have more than one superclass and inherit features from all parent classes. Please
note that Java does not support multiple inheritance with classes. In java, we can
achieve multiple inheritance only through Interfaces. In image below, Class C is
derived from interface A and B.
5. Hybrid Inheritance (Through Interfaces) : It is a mix of two or more of the
above types of inheritance. Since java doesn’t support multiple inheritance with
classes, the hybrid inheritance is also not possible with classes. In java, we can
achieve hybrid inheritance only through Interfaces.
A.M.Belicks
about:blank
Unit – 20 -AP
21 | P a g e
22/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Encapsulation
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that
binds together code and the data it manipulates. Another way to think about encapsulation is, it is a
protective shield that prevents the data from being accessed by the code outside this shield.
 Technically in encapsulation, the variables or data of a class is hidden from any other class
and can be accessed only through any member function of own class in which they are
declared.
 As in encapsulation, the data in a class is hidden from other classes, so it is also known
as data-hiding.
 Encapsulation can be achieved by Declaring all the variables in the class as private and
writing public methods in the class to set and get the values of variables
about:blank
23/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
In the above program the class
EncapsulateDemo is encapsulated as the
variables are declared as private. The get methods like getAge() , getName() , getRoll() are set
as public, these methods are used to access these variables. The setter methods like setName(),
setAge(), setRoll() are also declared as public and are used to set the values of the variables.
Class
A class is a user defined blueprint or prototype from which objects are created. It represents the set
of properties or methods that are common to all objects of one type. In general, class declarations
can include these components, in order:
1. Modifiers: A class can be public or has default access (Refer this for details).
2. Class name: The name should begin with a initial letter (capitalized by convention).
3. Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the
keyword extends. A class can only extend (subclass) one parent.
4. Interfaces(if any): A comma-separated list of interfaces implemented by the class, if
any, preceded by the keyword implements. A class can implement more than one
interface.
5. Body: The class body surrounded by braces, { }.
Example
class ClassName {
// fields
// methods
}
Object
It is a basic unit of Object-Oriented Programming and represents the real life entities. A typical
Java program creates many objects, which as you know, interact by invoking methods. An object
consists of:
 State: It is represented by attributes of an object. It also reflects the properties of an object.
 Behavior: It is represented by methods of an object. It also reflects the response of an object
with other objects.
 Identity: It gives a unique name to an object and enables one object to interact with other
objects.
A.M.Belicks
about:blank
Unit – 20 -AP
23 | P a g e
24/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example of an object: dog
(geeksforgeeks 2,2019)
Example
Message
Message Passing in terms of computers is communication between processes. It is a form of
communication used in object-oriented programming as well as parallel programming. Message
passing in Java is like sending an object i.e. message from one thread to another thread. It is
used when threads do not have shared memory and are unable to share monitors or semaphores
or any other shared variables to communicate. Suppose we consider an example of producer and
consumer, likewise what producer will produce, the consumer will be able to consume that only.
We mostly use Queue to implement communication between threads.
A.M.Belicks
about:blank
Unit – 20 -AP
24 | P a g e
25/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
In the example explained below, we will be using vector(queue) to store the messages, 7 at a
time and after that producer will wait for the consumer until the queue is empty.
In Producer there are two synchronized methods putMessage() which will call
form run() method of Producer and add message in Vector whereas getMessage() extracts the
message from the queue for the consumer.
Using message passing simplifies the producer-consumer problem as they don’t have to
reference each other directly but only communicate via a queue.
code
A.M.Belicks
about:blank
Unit – 20 -AP
25 | P a g e
26/88
7/30/23, 1:02 PM
A.M.Belicks
about:blank
803-1601900046139-Unit 40- Advanced Programming
Unit – 20 -AP
26 | P a g e
27/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
(geeksforgeeks,2020)
Aggregation
Aggregation
Aggregation is a special form of association. It is a relationship between two classes
like association, however its a directional association, which means it is strictly a one-way
association. It represents a HAS-A relationship.
A.M.Belicks
about:blank
Unit – 20 -AP
27 | P a g e
28/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Aggregation Example in Java
For example, consider two classes Student class and Address class. Every student has an address so
the relationship between student and address is a Has-A relationship. But if you consider its vice
versa then it would not make any sense as an Address doesn’t need to have a Student necessarily.
Let’s write this example in a java program.
Student Has-A Address
Output
123
Chaitanya
55
Agra
UP
India
The above example shows the Aggregation between Student and Address classes. You can see
that in Student class I have declared a property of type Address to obtain student address. It’s
a typical example of Aggregation in Java.
A.M.Belicks
about:blank
Unit – 20 -AP
28 | P a g e
29/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
(beginnersbook,2013)
Task 2
I) 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.
A.M.Belicks
about:blank
Unit – 20 -AP
29 | P a g e
30/88
7/30/23, 1:02 PM
A.M.Belicks
about:blank
803-1601900046139-Unit 40- Advanced Programming
Unit – 20 -AP
30 | P a g e
31/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Task 3
I.
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.
Design Patterns
Since a system is made up of static as well as dynamic elements, you will find patterns that can be
used for either of these types. For static elements of a system especially the architecture and design
of a system, there are design patterns - the focus of this article. The dynamic aspects of a system are
abstracted and captured as process patterns. But patterns are not limited to this. Patterns can be
abstracted for the implementation aspects of a system as well.
Based on how they are to be used, patterns are primarily categorized as:
 Creational
 Structural
 Behavioral
Creational
Creational patterns define mechanisms for instantiating objects. The implementation of the
creational pattern is responsible for managing the lifecycle of the instantiated object. A few
examples of Creational design patterns are listed below.
Factory
One of the easily recognized and frequently used design patterns is the Factory pattern. If you
have designed any object that is responsible for creating and maintaining the lifecycle of another
object, you have used the Factory pattern. Obtaining a database connection in your application
using a connection manager or connection factory object is a good example of the Factory
pattern.
Figure 1. Factory pattern
Singleton
A.M.Belicks
about:blank
Unit – 20 -AP
31 | P a g e
32/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
A singleton is another example of a
factory pattern. What makes the
Singleton pattern unique is that one and only one instance of the object can exist irrespective of
the number of times the object
is instantiated. The most common use of a Singleton pattern is for server applications like a Java
based Remote Method Invocation (RMI) server application.
Endpoint security is a cornerstone of IT security, so our team put considerable time and thought
into this list of top endpoint detection and response (EDR) vendors
Figure 2. Singleton pattern
Structural
The composition of objects and their organization to obtain new and varied functionality is the
underlying basis of Structural patterns. A few examples of Structural design patterns are listed
below.
Adapter
In the Adapter pattern, an object provides an implementation of an interface used by other
objects in a consistent way. The adapter object wraps different disparate implementations of the
interface and presents a unified interface for other objects to access. A good example of this is a
database driver like an ODBC (Open Database Connectivity) or JDBC (Java Database
Connectivity) driver that wraps the custom database accessing implementation for different
databases and yet, presents a consistent interface that is a published and standardized API.
Figure 3. Adapter pattern
Proxy
A.M.Belicks
about:blank
Unit – 20 -AP
32 | P a g e
33/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
A Proxy pattern constitutes use of proxy
objects during object interaction. A
proxy object acts as a substitute for the actual object. Use of proxy objects is prevalent in remote
object interaction protocols. As an example, when an object needs to interact with a remote
object, say across a network, the most preferred way of encapsulating and hiding the interaction
mechanism is by
using a proxy object that mediates communication between the requesting object and the remote
object.
Figure 4. Proxy pattern
Behavioral
Interaction between different objects is specifically covered by Behavioral patterns. Some
examples of behavioral patterns are given below.
Command
The Command pattern is commonly used for gathering requests from client objects and
packaging them into a single object for processing. The Command pattern allows for having
well defined command interfaces that are implemented by the object that provides the
processing for the client requests packaged as commands.
Figure 5. Command pattern
Iterator
A simple mechanism to traverse and access a list of objects is defined by the Iterator pattern. The
Iterator pattern encapsulates the internal implementation of the list while providing a
A.M.Belicks
about:blank
Unit – 20 -AP
33 | P a g e
34/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
standardized
traversal.
mechanism
for
list
Figure 6. Iterator pattern
(developer,2004)
Brief Example
Creational Patterns
Abstract Factory
- Do we need to create families of objects.
Factory method takes care of one product whereas the abstract factory Pattern provides a way to
encapsulate a family of products.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
34 | P a g e
35/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
We have a requirement where we need to create control library and the same library supports
multiple platforms but the client code should not be changed if we import from one operating
system to the other. The solution is
A.M.Belicks
about:blank
Unit – 20 -AP
35 | P a g e
36/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
The client uses the GuiFactory to get the required factory of the supported operating system and
calls the same Show Method. Now depending on the platform, we change the factory but the
client implementation remains the same. If support for new operating system is to be added we
need the new factory and the exact implementation of the buttons and without changing the
existing code we can support the new platform.
Builder
- Do we need to create object in several steps.
Builds a class based on requirements where Director asks the builder to build each of the parts.
Mainly the builder pattern is not used independently but other patterns may have builder pattern
as a part where they create the complicated objects using the builder.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
36 | P a g e
37/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
Who is what?
Waiter is Director
PizzaBuilder is Builder
CheesePizzaBuilder and MixedPizzaBuilder are Concretebuilder
Pizza is product
When Waiter (Director) is asked to serve it creates the Pizza (Product) using the PizzaBuilder.
A.M.Belicks
about:blank
Unit – 20 -AP
37 | P a g e
38/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Another example could be Maze which
complicated object build from walls and
is a
rooms.
Factory
- Do we need to have derived classes figure out what to instantiate and decouple client from
instantiated class.
Client uses the factory to create products and its the factory which decides when the actual
product is needed for instantiation. This way client decouples the instance and can be saved
from some of the crucial operations of object copy if the type of object may change after
creation.
Typically the class diagram looks like
Example
A.M.Belicks
about:blank
Unit – 20 -AP
38 | P a g e
39/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Who is what?
ComputerFactory (Creator)
ConcreteComputerFactory (ConcreteCreator)
Processor (Product)
ConcreteProcessor (ConcreteProduct)
When the GetProcessor of ComputerFactory is called its the ConcreteComputerFactory creates
the ConcreteProcessor and the creation of ConcreteProcessor is delayed till we call
the GetProcessor() function.
Another good example could be logging, where we create the instance of the logger factory but
instantiate the logger class when actual logging is done.
Prototype
- Do we have too many classes to instantiate / or is the object creation a cumbersome process.
Mainly we don't create the objects of a class directly but clone the existing object and change the
state of the object as needed. The main application of such pattern is when the object creation is
costly. As an example we have a database class the constructor sets up the database for the class.
Now for each new user logging to the system once the system is up we don't setup the database
but just clone the first object and change the user specific details like user name / password to
A.M.Belicks
about:blank
Unit – 20 -AP
39 | P a g e
40/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
validate the user.
Typically the class diagram looks like
Example
I would not explain here who is what because its pretty much evident.
A.M.Belicks
about:blank
Unit – 20 -AP
40 | P a g e
41/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Singleton
- Do we need to limit the no of objects of a class.
Ensures only one (n = 1..n) instance. The pattern explains how you can achieve the singleton class.
It says to have the constructor as private and have a static method to access the instance of the class
using that method.
Typically the class diagram looks like
Example
I would not explain here who is what because it’s pretty much evident.
Structural Patterns
Adapter
- Do we have the right stuff but wrong interface.
We use the adapter design pattern where the requirements is to convert between one interface to
A.M.Belicks
about:blank
Unit – 20 -AP
41 | P a g e
42/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
another. Adapter pattern is never
implemented when designing a new
system but with the changing requirements we have deferring interfaces then adapter comes into
picture.
Typically the class diagram looks like
Example
We have used some library where we have Add function which takes two integer and provides
the sum of them. Now when upgrading the library we find that the library has changed the Add
function such that it takes 2 floating point number. Now one option could be to change all the
client code where we have used the Add method or other option is to have an Adapter.
A.M.Belicks
about:blank
Unit – 20 -AP
42 | P a g e
43/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
CalcAdapter calls the necessary library function after making the necessary changes (in our
example conversion between the data types)
Bridge
- Do we have one variation using another variation in a varying way.
Decouple an abstraction from its implementation so that two can vary independently. In strategy
pattern we decouple the behavior but in Bridge we decouple the abstraction.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
43 | P a g e
44/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
In Abstract Factory we discussed about the problem of creating a control library for various
operating system. Now creating the library from the scratch is never a good idea and so we may
need to use some of the existing infrastructure or library available. We may use the XWindow
toolkit or MacWindow toolkit as the base depending on the user platform and toolkit available.
The DrawRect actually uses the DrawLine function which actually is dependent on the type of
implementation and we seperate the implementation from the abstraction and have a link ( or
bridge ) between the two.
A.M.Belicks
about:blank
Unit – 20 -AP
44 | P a g e
45/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Composite
- Do we have units and groups and want to treat them the same way.
Compose the objects in a tree structure where individual objects as well as the composed objects
behave uniformly. Composed objects delegates the requests to the individual leaf objects.
Typically the class diagram looks like
Example
We have some simple graphics and have some graphics which are composed of these simple
graphics and as a client both should behave uniformly.
A.M.Belicks
about:blank
Unit – 20 -AP
45 | P a g e
46/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Folder browsing could be other example where from the client's point of view its an operation
on the folder tree irrespective of its folder (composite object) or file ( leaf object ).
Decorator
- Do we need multiple additional functions we may need to apply, but which and how many we
add varies, without sub classing.
Attach additional responsibilities to an object dynamically. It has the capability of performing
some additional operations before or after the basic operation.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
46 | P a g e
47/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
Say we have a FileReader class where the file can be read based on the combination of applying
any of the formulas like it could be




Zipped.
Encrypted.
Zipped and encrypted.
encrypted then zipped and ecrypted again.
The solution is Decorator pattern where we apply the options based on the requirement.
Code: CSharp
FileReader file = new FileReader();
// Zip the File
ZipReader zip = new ZipReader(file);
// Encrypt the zip file
EncryptedReader enc = new EncryptedReader(zip);
A.M.Belicks
about:blank
Unit – 20 -AP
47 | P a g e
48/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
enc.Read();
Code: CSharp
FileReader file = new FileReader();
// Encrypt the file
enc = new EncryptedReader(file);
// Zip the encrypted file
zip = new ZipReader(enc);
zip.Read();
We can apply any combination as and when needed and also new methods of encryption is very
simple. Just add the new class as sibling of EncryptedReader
Facade
A.M.Belicks
about:blank
Unit – 20 -AP
48 | P a g e
49/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
- Do we want simplify, beautify or OOan existing class or subsystem.
fy
When client is decoupled from the system using an inter mediator its called facade. Facade
behaves as a door to subsystem and provides a single interface to complex interface in the
subsystem. Here a point to note is that the subsystem should not have a dependency on the
FACADE and if thats the case then the facade is a part of the sub-system and it should move into
the sub-system and we should have a new facade class.
Also Facade is not the only entry point to the sub-system but is a convenient point of
communication to the subsystem and client can always have the direct access to the subsystem.
This methods helps in developing the subsystem independently without affecting the clients
using them.
Typically the class diagram looks like
Example
We have a Car System creation where the car is created based on the complex subsystems like
wheel, steering, chassis, body ...
A.M.Belicks
about:blank
Unit – 20 -AP
49 | P a g e
50/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Flyweight
- Do we have too many part objects.
Any objects state can be classified into two types of data that it can store one is intrinsic (static
and independent of object) and one is extrinsic (non-static and depend on the state of the object)
then flyweight pattern can be applied. The design pattern is useful when we have large no of
objects which can be grouped once the extrinsic state is removed and it uses de-encapsulation to
split the objects.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
50 | P a g e
51/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
We have some shape objects and the shape objects are really costly and so we can have the
shape object split itself such that some data which is independent of the state of the object is
kept in the object and other data is provided externally. Say in our shape object how the shape is
drawn is same but where the shape is drawn is dependent on the state of the object and so the
print method should know where to print which is extrinsic and should be supplied.
A.M.Belicks
about:blank
Unit – 20 -AP
51 | P a g e
52/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Proxy
- Do we need to optionally add some new functionality to something that already exists. Do we
need to control how an object is accessed.
It provides a placeholder for another objects and the proxy object gives the impression to the
client that actual request is handled by the proxy but it just delegates the request to the real
subject.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
52 | P a g e
53/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
Say we have a system setup where we send and receive data over the network. Now due to some
security reasons data are encrypted and so now they need to be decrypted before processing and
so now we are in trouble because all the client code needs to be changed to decrypt the data or
we may need to change the stable library code which use to send/recieve the data. Now the
solution could be to have the proxy which will do the additional responsibility given to the
system and then send the data using the well tested system in place.
A.M.Belicks
about:blank
Unit – 20 -AP
53 | P a g e
54/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
We should be using the proxy system
where we think we may need to add
some additional responsibilities later.
Behavioral Patterns
Chain of Responsibility
- Do we have diff. objects that can do the job but we do not want the client object know which
is actually going to do it.
Avoid coupling the sender of a request to its reciever by giving more than one object a chance to
handle the request. Helps in reducing the coupling though they are chained, but does not know
about other objects apart fron the fact that they derive from the common interface.
Best example could be Context help where the each help component tries to perform the request
and when fail they pass the request in the chain to other members.
Typically the class diagram looks like
Example
In the banking system where cheque's for clearing is approved by the person but if the cheque
amount is beyond certain limit, the approving responsibility moves the person higher in
authority in the bank.
Windows messaging system works in the similar method where the messages are processed by
the controls if the point likes with the bounds of the control or goes to the parent.
A.M.Belicks
about:blank
Unit – 20 -AP
54 | P a g e
55/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Command
- Do we need to decouple request from handler.
Encapsulate requests for service from an object inside other object(s) and manipulate requests.
Command objects are mainly helpful in undo/redo operation where the previous state can be
saved for reloading or even the necessary command(s) can be stored in stack for the same.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
55 | P a g e
56/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
Say we have designed an image editor and user can have the option of opening file from various
ways like menu, tool bar, double click on a file in the explorer. The solution is the command
pattern where the FileOpen command is associated in the viewer itself and when the command
executes the file is shown in the viewer.
The other example could be the operations on the images.
Interpreter
As the name suggest it interpret your expression. Some expressions are atomic and some
complex which are made up of atomic and it interprets the atomic and complex expressions
uniformly. It mainly uses in the compilers / parsers / Macro expansions.
A.M.Belicks
about:blank
Unit – 20 -AP
56 | P a g e
57/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
I have not provided any sample because this one is not that often used just for completeness of
the article have mentioned the pattern here.
Iterator
- Do we want to separate collection from client that's using.
Provide a way to access the elements of an aggregate objects sequentially without exposing its
representation. We can make the client independent on the movement of the cursors like forward
traversal / backward traversal as well as the internal implementation of the list.
Typically the class diagram looks like
A.M.Belicks
about:blank
Unit – 20 -AP
57 | P a g e
58/88
7/30/23, 1:02 PM
803-1601900046139-Unit 40- Advanced Programming
Example
I would not explain here who is what because its pretty much evident and nowadays any modern
language supports this and so you could use the foreach loop. In C-Sharp if you would like to
have a class that will be a list you need to use the IEnumerator and IEnumerable interfaces and
A.M.Belicks
about:blank
Unit – 20 -AP
58 | P a g e
59/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
60/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
61/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
62/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
63/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
64/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
65/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
66/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
67/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
68/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
69/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
70/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
71/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
72/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
73/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
74/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
75/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
76/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
77/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
78/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
79/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
80/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
81/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
82/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
83/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
84/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
85/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
86/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
87/88
7/30/23, 1:02 PM
about:blank
803-1601900046139-Unit 40- Advanced Programming
88/88
Download