0% found this document useful (0 votes)
41 views

803 1601900046139 Unit 40 Advanced Programming

adanvaced

Uploaded by

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

803 1601900046139 Unit 40 Advanced Programming

adanvaced

Uploaded by

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

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)


INTERNAL VERIFICATION – ASSESSMENT DECISIONS
Programme title HND in Computing - Application Dev / Software Eng. Pathway

Assessor Internal Verifier


Unit 20 – Advance Programming
Unit(s)

Assignment title

Student’s name Sajidh shukoor


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

INTERNAL VERIFIER CHECKLIST

Do the assessment criteria awarded match


those shown in the assignment brief? Y/N

Is the Pass/Merit/Distinction grade awarded


justified by the assessor’s comments on the Y/N
student work?
Has the work been assessed
Y/N
accurately?
Is the feedback to the student:
Give details:
• Constructive? Y/N
• Linked to relevant assessment criteria? Y/N
• Identifying opportunities for Y/N
improved performance?
• Agreeing actions? Y/N
Does the assessment decision need
Y/N
amending?

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date

Confirm action completed


Remedial action taken
Give details:

Assessor signature Date


Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID Sajidh Shukoor COL/E-008595

Unit Title Unit 20 – Advance Programming

Assignment Number 1 Assessor


Date Received
Submission Date
1st submission
Date Received 2nd
Re-submission Date
submission
Assessor Feedback:
LO1 Demonstrate a range of interpersonal and transferable communication skills to a target audience

Pass, Merit & Distinction P1 P2 M1 D1


Descripts

LO2 Apply critical reasoning and thinking to a range of problem-solving scenarios

Pass, Merit & Distinction P3 P4 M2 M3 D2


Descripts

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 M5 D4
Descripts

Grade: Assessor Signature: Date:

Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

Signature & Date:

* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and
grades decisions have been agreed at the assessment board.
Assignment Feedback
Formative Feedback: Assessor to Student

Action Plan

Summative feedback

Feedback: Student to Assessor

Assessor Date
signature

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

1. A Cover page or title page – You should always attach a title page to your assignment. Use
previous page as your cover sheet and make sure all the details are accurately filled.
2. Attach this brief as the first section of your assignment.
3. All the assignments should be prepared using a word processing software.
4. All the assignments should be printed on A4 sized papers. Use single side printing.
5. Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.

Word Processing Rules

1. The font size should be 12 point, and should be in the style of Time New Roman.
2. Use 1.5 line spacing. Left justify all paragraphs.
3. Ensure that all the headings are consistent in terms of the font size and font style.
4. Use footer function in the word processor to insert Your Name, Subject, Assignment No,
and Page Number on each page. This is useful if individual sheets become detached for any
reason.
5. Use word processing application spell check and grammar check function to help editing
your assignment.

Important Points:

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

I hereby, declare that I know what plagiarism entails, namely to use another’s work and to present
it as my own without attributing the sources in the correct form. I further understand what it
means to copy another’s work.

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


2. I understand the plagiarism and copying policy of Edexcel UK.
3. I know what the consequences will be if I plagiarise or copy another’s work in any of the
assignments for this program.
4. I declare therefore that all work presented by me for every aspect of my program, will be my
own, and where I have made use of another’s work, I will attribute the source in the correct
way.
5. I acknowledge that the attachment of this document signed or not, constitutes a binding
agreement between myself and Pearson, UK.
6. I understand that my assignment will not be considered as submitted if this document is not
attached to the assignment.

[email protected]
Student’s Signature: Date:13/08/2021
(Provide E-mail ID) (Provide Submission Date)
Higher National Diploma in Business
Assignment Brief
Student Name /ID Number

Unit Number and Title Unit 20 – Advance Programming

Academic Year 2020/21


2018/19
Unit Tutor

Assignment Title

Issue Date

Submission Date

IV Name & Date

Submission format

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

The recommended word count is 4,000–4,500 words for the report excluding annexures. Note
that word counts are indicative only and you would not be penalised for exceeding the word
count.
Unit Learning Outcomes:

Learning Outcomes
By the end of this unit students will be able to:
LO1. Examine the key components related to the object-orientated programming
paradigm, analysing design pattern types.
LO2. Design a series of UML class diagrams.
LO3. Implement code applying design patterns.
LO4 Investigate scenarios with respect to design patterns.
Assignment Brief and Guidance:

BOC Software solutions is leading software company in Kandy as system analyst you have to build
an application for Family Dental Care (FDC) considering given scenario.

Family Dental Care (FDC) is a leading up market dental surgery located in Kandy. It provides all
types of dental treatments to patients which include extractions, nerve fillings, maxillofacial
surgeries (i.e. surgeries involving jaw bone) and sophisticated dental implants. It is visited by
prominent dentists and dental consultants with post graduate qualifications, some of whom are
working at the Faculty of Dental Science at the University of Peradeniya.
Patients consult doctors by appointment. On their first visit, patients are required to register by
entering their personal details such as name, address, national identity card number and
contact number. A small fee is charged from the patient during registration. A separate fee is
charged for each treatment given.
Doctors too must get registered at FDC by providing personal details such as name, address,
date of birth, national ID number and contact number. In addition, consultants must provide the
name of their post graduate qualification along with the country of the University that granted it
and ordinary dentists should indicate the number of years of experience.
FDC consists of four fully equipped surgery rooms so that four patients can be accommodated at
any given time. FDC also contains a dental scan room which can be attended by one patient at a
time. The dental scan machine is operated by one of the dentists of the FDC facility. Normally, a
dentist without appointments for a given time slot (say, between 5 PM and 6 PM) is assigned to
the machine by the manager. When that time slot finishes, another doctor who is free will be
assigned.
The staff of FDC is made up of a manager, four nurses (one for each of the four surgery rooms)
and a receptionist who handles registrations and appointments.
An information system is required to keep track of patients, doctors, appointments, treatments
given to patients and payments. The system must also maintain information about the staff. It
has been decided to use an object oriented approach to design and implement the system.

Task 1
Examine the Object oriented concepts given below. Provide diagrams and code snippets from
suitable specific programming language to supplement your explanations.
i) Class
ii) Object
iii) Message
iv) Encapsulation
v) Inheritance
vi) Polymorphism
vii) Aggregation/composition

Task 2
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
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.
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

Grading Criteria Achieve Feedback


d
LO1 Examine the key components
related to the
object-orientated programming
paradigm,
analyzing design pattern types

P1 Examine the characteristics of the


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

D1 Analyse the relationship between the


object-orientated paradigm and design
patterns.

LO2 Design a series of UML class


diagrams
P2 Design and build class diagrams using
a UML tool.
M2 Define class diagrams for specific
design patterns using a UML tool.
D2 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.

M4 Reconcile the most


appropriate design
pattern from a range with a series of
given scenarios.
Task 01

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:

Modifiers: A class can be public or has default access (Refer this for details).
Class name: The name should begin with a initial letter (capitalized by convention).
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.
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.
Body: The class body surrounded by braces, { }.

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.
Example of an object: dog

Message Passing: Objects communicate with one another by sending and receiving information to
each other. A message for an object is a request for execution of a procedure and therefore will
invoke a function in the receiving object that generates the desired results. Message passing
involves specifying the name of the object, the name of the function and the information to be sent.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and
Collections concepts with the Fundamentals of Java and Java Collections Course at a student-
friendly price and become industry ready.

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

polymorphism

The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form.

Real life example of polymorphism: A person at the same time can have different characteristic.
Like a man at the same time is a father, a husband, an employee. So the same person posses
different behavior in different situations. This is called polymorphism.

Polymorphism is considered one of the important features of Object-Oriented Programming.


Polymorphism allows us to perform a single action in different ways. In other words,
polymorphism allows you to define one interface and have multiple implementations. The word
“poly” means many and “morphs” means forms, So it means many forms.
In Java polymorphism is mainly divided into two types:

Compile time Polymorphism


Runtime Polymorphism

Compile-time polymorphism: It is also known as static polymorphism. This type of polymorphism


is achieved by function overloading or operator overloading. But Java doesn’t support the Operator
Overloading.
Method Overloading: When there are multiple functions with same name but different parameters

then these functions are said to be overloaded. Functions can be overloaded by change in number
of arguments or/and change in type of arguments.

Example: By using different types of arguments


Runtime polymorphism: It is also known as Dynamic Method Dispatch. It is a process in which a
function call to the overridden method is resolved at Runtime. This type of polymorphism is
achieved by Method Overriding.

Method overriding, on the other hand, occurs when a derived class has a definition for one of the
member functions of the base class. That base function is said to be overridden.

Example:
Association is relation between two separate classes which establishes through their Objects.
Association can be one-to-one, one-to-many, many-to-one, many-to-many.
In Object-Oriented programming, an Object communicates to other Object to use functionality and
services provided by that object. Composition and Aggregation are the two forms of association.
n above example two separate classes Bank and Employee are associated through their Objects.
Bank can have many employees, So it is a one-to-many relationship.

Aggregation

Aggregation

It is a special form of Association where:


 It represents Has-A relationship.
 It is a unidirectional association i.e. a one way relationship. For example, department
can have students but vice versa is not possible and thus unidirectional in nature.
In Aggregation, both the entries
survive individually which means ending one entity will effect the other entity

Output:

Total students in institute: 4


In this example, there is an Institute which has no. of departments like CSE, EE. Every department
has no. of students. So, we make a Institute class which has a reference to Object or no. of Objects
(i.e. List of Objects) of the Department class. That means Institute class is associated with
Department class through its Object(s). And Department class has also a reference to Object or
Objects (i.e. List of Objects) of Student class means it is associated with Student class through its
Object(s).
It represents a Has-A relationship.

When do we use Aggregation ??


Code reuse is best achieved by aggregation.

Composition
Composition

Composition is a restricted form of Aggregation in which two entities are highly dependent
on each other.

 It represents part-of relationship.


 In composition, both the entities are dependent on each other.
 When there is a composition between two entities, the composed object
cannot exist without the other entity.

Aggregation vs Composition
1. Dependency: Aggregation implies a relationship where the child can exist
independently of the parent. For example, Bank and Employee, delete the Bank
and the Employee still exist. whereas Composition implies a relationship where
the
child cannot exist independent of the parent. Example: Human and heart, heart
don’t exist separate to a Human
2. Type of Relationship: Aggregation relation is “has-a” and composition is
“part- of” relation.
3. Type of association: Composition is a strong Association whereas Aggregation
is a weak Association.

Task 4

A design pattern is a repeatable solution to a software engineering problem. Unlike most


program-specific solutions, design patterns are used in many programs. Design patterns are not
considered finished product; rather, they are templates that can be applied to multiple situations
and can be improved over time, making a very robust software engineering tool. Because
development speed is increased when using a proven prototype, developers using design pattern
templates can improve coding efficiency and final product readability.
Design patterns represent the best practices used by experienced object-oriented software
developers. Design patterns are solutions to general problems that software developers faced
during software development. These solutions were obtained by trial and error by numerous
software developers over quite a substantial period of time.
sage of Design Pattern

Design Patterns have two main usages in software development.

Common platform for developers

Design patterns provide a standard terminology and are specific to particular scenario. For
example, a singleton design pattern signifies use of single object so all developers familiar with
single design pattern will make use of single object and they can tell each other that program is
following a singleton pattern.
Best Practices

Design patterns have been evolved over a long period of time and they provide best solutions to
certain problems faced during software development. Learning these patterns helps
unexperienced developers to learn software design in an easy and faster way.

Types of Design Patterns

As per the design pattern reference book Design Patterns - Elements of Reusable Object-
Oriented Software , there are 23 design patterns which can be classified in three categories:
Creational, Structural and Behavioral patterns. We'll also discuss another category of design
pattern: J2EE design patterns.

S.N Pattern & Description


1 Creational Patterns
These design patterns provide a way to create objects while hiding the creation
logic, rather than instantiating objects directly using new operator. This gives
program more flexibility in deciding which objects need to be created for a given
use case.
2 Structural Patterns
These design patterns concern class and object composition. Concept of inheritance
is used to compose interfaces and define ways to compose objects to obtain new
functionalities.
3 Behavioral Patterns
These design patterns are specifically concerned with communication between
objects.
4 J2EE Patterns
These design patterns are specifically concerned with the presentation tier. These
patterns are identified by Sun Java Center.

Why are Design Patterns Important?

Short: They help us solve recurring design problems. Note that : design patterns don’t solve
the problem themselves, they help us solve the problem.

Detailed answers:
Communication, Learning and Enhanced Insight:

 Over the last decade design patterns have become part of every developer’s
vocabulary. This really helps in communication. One can easy tell another
developer on the team, “I’ve used Command pattern here” and the other
developer understands not just the design, but can also easily figure out the
rationale behind it. Design Patterns really help in learning, esp. when you are new
on a project. Also this helps in providing developers with better insight about
parts of the application or 3rd party frameworks they use.
Decomposing System into Objects :

 The hard part about OO Design is finding the appropriate objects and
decomposing a system. One has to think about encapsulation, granularity,
dependencies, flexibility, performance, evolution, reusability and so on. They all
influence decomposition, often in conflicting ways. Design Patterns really helps
identify less obvious abstractions. These objects are seldom found during analysis
or even the early design, they’re discovered later in the course of making a design
more flexible and reusable.

Determining Object Granularity:

 One thing I struggle a lot with is finding the right level of abstraction and
granularity. Design patterns helps in coming up with objects with different levels of
granularity that makes sense.

Specifying Object Interface :

 Identifying the right interface and the relationship between various interface is not a
one-shot activity. Usually it takes several iterations to identify the right composition of
interfaces. Forget interfaces, most of the times, coming up with a method signature can
also be quite tricky. Design Patterns really helps in this area.

Specifying Object Implementation :

 How should we implement an Object? Given an interface there could be multiple


concrete classes of that type, each one can have very different implementations. Design
Patterns provide guidance like Program to an interface (type) not an implementation
(concrete class) which can result in really good OO code.

Ensuring right reuse mechanism :

 When to use Inheritance, when to use Composition, when to use Parameterized Types?
Is delegation the right design decision in this context? There are various questions that
comes to a programmer’s mind when they are trying to design highly reusable and
maintainable code.
Knowledge of design patterns can really come handy when making such decisions.

Relating run-time and compile time structures :

 An object oriented program’s run-time structure often bares little resembles to this code
structure. Sometimes looking at the code does not give us the insights into run-time
structure. Knowledge of design patterns can make some of the hidden structure obvious.
Designing for change :

 We all know that lack of continuous refactoring and design that doesn’t take change into
account risks major redesign in the future. Over the years we’ve also learnt that big
upfront designs can’t standup against the constant change/additon of software
requirements. We’ve leant grouping elements with similar change life cycle together
yields in far more flexible and extendable design. If we think some behavior or element
of behavior is most likely to change, we try to abstract that behavior in one place. While
we understand these concepts are important design patterns really make it possible to
design such systems. Each design pattern lets some aspect of the system structure vary
independently of other aspects, thereby making a system more robust to a particular kind
of change.

4.2 Design pattern could come to assistance & UML diagram and an implementation for the
pattern recommended
Singleton design pattern

Singleton pattern is one of the simplest design patterns in Java. This type of design pattern
comes under creational pattern as this pattern provides one of the best ways to create an
object.

This pattern involves a single class which is responsible to create an object while making sure
that only single object gets created. This class provides a way to access its only object which can
be accessed directly without need to instantiate the object of the class.

[ CITATION tut181 \l 1033 ]

Structure
36

Make the class of the single instance responsible for access and "initialization on first use". The
single instance is a private static attribute. The accessor function is a public static method.
[ CITATION sou181 \l 1033 ]
37

4.3 Suitable Design pattern for handling this requirement & specific UML class diagram and
Implement design
Adapter Pattern

This pattern is easy to understand as the real world is full of adapters. For example
consider a USB to Ethernet adapter. We need this when we have an Ethernet interface on
one end and USB on the other. Since they are incompatible with each other. we use an
adapter that converts one to other. This example is pretty analogous to Object Oriented
Adapters. In design, adapters are used when we have a class (Client) expecting some type
of object and we have an object (Adaptee) offering the same features but exposing a
different interface.

To use an adapter:

1. The client makes a request to the adapter by calling a method on it using the target interface.
2. The adapter translates that request on the adaptee using the adaptee interface.
3. Client receive the results of the call and is unaware of adapter’s presence.

Definition:

The adapter pattern convert the interface of a class into another interface clients
expect. Adapter lets classes work together that couldn’t otherwise because of
incompatible interfaces.

4.4 Design pattern enable to obtain the additional functionality required by the queue
Supplement your answer with a UML class diagram
38

Iterator Pattern
Iterator Pattern is a relatively simple and frequently used design pattern. There are a lot of data
structures/collections available in every language. Each collection must provide an iterator that
lets it iterate through its objects. However while doing so it should make sure that it does not
expose its implementation.
Suppose we are building an application that requires us to maintain a list of notifications.
Eventually, some part of your code will require to iterate over all notifications. If we
implemented your collection of notifications as array you would iterate over them as:

And if it were some other collection like set, tree etc. way of iterating would change slightly. Now,
what if we build an iterator that provides a generic way of iterating over a collection independent of
its type.
39

Iterator pattern lets us do just that. Formally it is defined as below:


The iterator pattern provides a way to access the elements of an aggregate object without
exposing its underlying representation.

Class Diagram:

Here we have a common interface Aggregate for client as it decouples it from the implementation of
your collection of objects. The Concrete Aggregate implements createIterator() that returns iterator
for its collection. Each Concrete Aggregate’s responsibility is to instantiate a ConcreteIterator that
can iterate over its collection of objects. The iterator interface provides a set of methods for
traversing or modifying the collection that is in addition to next()/hasNext() it can also provide
functions for search, remove etc. Let’s understand this through an example. Suppose we are creating
a notification bar in our application that displays all the notifications which are held in a notification
collection. NotificationCollection provides an iterator to iterate over its elements without exposing
how it has implemented the collection (array in this case) to the Client (NotificationBar).

References

beginnersbook, 2018. beginnersbook. [Online]


Available at: https://beginnersbook.com/2013/05/aggregation/
[Accessed 2019].
blog.usejournal, 2018. blog.usejournal. [Online]
Available at: https://blog.usejournal.com/object-oriented-programming-concepts-in-simple-english-
3db22065d7d0
[Accessed 2019].
geeksforgeeks, 2018. geeksforgeeks. [Online]
Available at: https://www.geeksforgeeks.org/association-composition-aggregation-java/
[Accessed 2019].
40

geeksforgeeks, 2018. geeksforgeeks. [Online]


Available at: https://www.geeksforgeeks.org/adapter-pattern/
[Accessed 2019].
geeksforgeeks, 2018. geeksforgeeks. [Online]
Available at: https://www.geeksforgeeks.org/iterator-pattern/
[Accessed 2019].
guru99, 2018. guru99. [Online]
Available at: https://www.guru99.com/java-class-inheritance.html
[Accessed 2019].
sourcemaking, 2018. sourcemaking. [Online]
Available at: https://sourcemaking.com/design_patterns
[Accessed 2019].
sourcemaking, 2018. sourcemaking. [Online]
Available at: https://sourcemaking.com/design_patterns/singleton
[Accessed 2019].
techopedia, 2019. [Online].
tutorialspoint, 2018. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/java/java_polymorphism
[Accessed 2019].
tutorialspoint, 2018. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/design_pattern/singleton_pattern
[Accessed 2019].

You might also like