Design Patterns. Collectional Patterns. Session objectives 11/06/2012. Introduction. Composite pattern. Iterator pattern

Similar documents
16/07/2012. Design Patterns. By Võ Văn Hải Faculty of Information Technologies - HUI. Behavioral Patterns. Session objectives. Strategy.

Chapter 1 Introduction. What is a Design Pattern? Design Patterns in Smalltalk MVC


Visitor. Intent. Motivation

Preparing a REST API. Rules of REST APIs, API patterns, Typical CRUD operations


Infrastructure Series

UFuRT: A Work-Centered Framework and Process for Design and Evaluation of Information Systems

Maximo Reporting: Maximo-Cognos Metadata

UML : MODELS, VIEWS, AND DIAGRAMS

Sometimes it's necessary to issue requests to objects without knowing anything about the operation being requested or the receiver of the request.

Structure Query Language (SQL)

Java Programming Course IO

App Orchestration 2.6


Common Language Runtime

Composition class is responsible for maintaining and updating the linebreaks of text displayed in a text viewer.


Cisco Tetration Analytics, Release , Release Notes

Developing Microsoft SharePoint Server 2013 Core Solutions

In Java, we can use Comparable and Comparator to compare objects.

Data Structure Interview Questions

MyUni Adding Content. Date: 29 May 2014 TRIM Reference: D2013/ Version: 1

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Getting the Most from REST and JSON

Querying Data with Transact SQL

I - EDocman Installation EDocman component EDocman Categories module EDocman Documents Module...2

Chain of Responsibility

STEREO VISION WITH COGNIMEM

Element Creator for Enterprise Architect

Proper Document Usage and Document Distribution. TIP! How to Use the Guide. Managing the News Page

Laboratory #13: Trigger

Table of Contents. 1 Introduction Connecting to the API HTTP request syntax API release versions... 4

Tree Processing (DOM)

Assignment #5: Rootkit. ECE 650 Fall 2018

Lab 4. Name: Checked: Objectives:

Interfacing to MATLAB. You can download the interface developed in this tutorial. It exists as a collection of 3 MATLAB files.

SW-G using new DryadLINQ(Argentia)

Overview. Enhancement for Policy Configuration Module

Last time. VHDL in Action. Motivation. Covered in This Lesson. Packages. Packages (cont'd)

Oracle Database 11g Replay: The In-built Recorder for Real Application Testing

Overview of OPC Alarms and Events

Oracle FLEXCUBE Universal Banking Development Workbench- Screen Development II

Extensible Query Processing in Starburst

Element Creator for Enterprise Architect

B Tech Project First Stage Report on

LiveEngage and Microsoft Dynamics Integration Guide Document Version: 1.0 September 2017

To over come these problems collections are recommended to use. Collections Arrays

Synoptic Display Studio Developers Guide

One reason for controlling access to an object is to defer the full cost of its creation and initialization until we actually need to use it.

Creating Relativity Dynamic Objects

TRAINING GUIDE. Lucity Mobile

ISTE-608 Test Out Written Exam and Practical Exam Study Guide

Java Database Connectivity

Ascii Art Capstone project in C

Java Database Connectivity

Please contact technical support if you have questions about the directory that your organization uses for user management.

SmartPass User Guide Page 1 of 50

Lecture 6 -.NET Remoting

Creating a TES Encounter/Transaction Entry Batch

Pages of the Template

CONTROL-COMMAND. Software Technical Specifications for ThomX Suppliers 1.INTRODUCTION TECHNICAL REQUIREMENTS... 2

WEB LAB - Subset Extraction

Retrieval Effectiveness Measures. Overview

Troubleshooting of network problems is find and solve with the help of hardware and software is called troubleshooting tools.

IMPORTING INFOSPHERE DATA ARCHITECT MODELS INFORMATION SERVER V8.7

MacroFlo User Guide. IES Virtual Environment 6.5. Macroflo. VE 6.5 MacroFlo 1

$ARCSIGHT_HOME/current/user/agent/map. The files are named in sequential order such as:

Getting Started with the Web Designer Suite

To start your custom application development, perform the steps below.

TRAINING GUIDE. Overview of Lucity Spatial

Objectives. Topic 8: Input, Interaction, & Introduction to callbacks. Input Devices. Project Sketchpad. Introduce the basic input devices

History of Java. VM (Java Virtual Machine) What is JVM. What it does. 1. Brief history of Java 2. Java Version History

Creating Relativity Dynamic Objects

Cortex Quick Reference Supplier Guide Service Receipt Rejections for Husky Suppliers

INSTALLING CCRQINVOICE

Principles of Programming Languages

ECE 545 Project Deliverables

CITI Technical Report 08-1 Parallel NFS Block Layout Module for Linux

Essentials for IBM Cognos BI (V10.2) Day(s): 5. Overview

The following screens show some of the extra features provided by the Extended Order Entry screen:

2. What is the most cost-effective method of solving interface congestion that is caused by a high level of traffic between two switches?

CAMPBELL COUNTY GILLETTE, WYOMING

The QMF Family V Newsletter 3rd Quarter 2013 Edition

Dynamic Storage (ECS)

Planning, installing, and configuring IBM CMIS for Content Manager OnDemand

Enterprise Chat and Developer s Guide to Web Service APIs for Chat, Release 11.6(1)

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C

It has hardware. It has application software.

Users, groups, collections and submissions in DSpace. Contents

In order to authenticate with the service, you will need to call the following endpoint:

Apply IU Admin Center

OVAL Language Design Document

CS1150 Principles of Computer Science Introduction (Part II)

Lab 5 Sorting with Linked Lists

Applet: Java program that are typically embedded in XHTML documents.

CaseWare Working Papers. Data Store user guide

Faculty Textbook Adoption Instructions

BANNER BASICS. What is Banner? Banner Environment. My Banner. Pages. What is it? What form do you use? Steps to create a personal menu

Implementation of Authentication Mechanism for a Virtual File System

Transcription:

Design Patterns By Võ Văn Hải Faculty f Infrmatin Technlgies HUI Cllectinal Patterns Sessin bjectives Intrductin Cmpsite pattern Iteratr pattern 2 1

Intrductin Cllectinal patterns primarily: Deal with grups r cllectins f bjects Deal with the details f hw t cmpse classes and bjects t frm larger structures Cncentrate n the mst efficient way f designing a class s that its instances d nt carry any duplicate data Allw the definitin f peratins n cllectins f bjects 3 Cllectinal Patterns Cmpsite pattern 4 2

Cmpsite pattern Mtivatin Example Let us create an applicatin t simulate the Windws/UNIX file system. The file system cnsists mainly f tw types f cmpnents directries and files. Directries can be made up f ther directries r files, whereas files cannt cntain any ther file system cmpnent. In this aspect, directries act as nn- terminal ndes and files act as terminal ndes f a tree structure. 5 Cmpsite pattern Mtivatin Example First apprach 6 3

Cmpsite pattern Mtivatin Example First apprach prblem When the client wants t query any f these bjects fr its size, it can simply invke the getcmpnentsize methd. The client treats bth the FileCmpnent and the DirCmpnent bject in the same manner. N separate cde is required t query FileCmpnent bjects and DirCmpnent bjects fr their size. But when call getcmpnent r addcmpnent methd, client must check t make sure that the FileSystemCmpnent bject it is wrking with is in fact a DirCmpnent bject. 7 8 4

Cmpsite pattern Mtivatin Example Secnd apprach 9 Cmpsite pattern Mtivatin Example Secnd apprach bjectives Prvide the same advantage f allwing the client applicatin t treat bth the cmpsite DirCmpnent and the individual FileCmpnent bjects in a unifrm manner while invking the getcmpnentsize methd Free the client applicatin frm having t check t make sure that the FileSystemCmpnent it is dealing with is an instance f the DirCmpnent class while invking any f the cmpsitespecific methds such as addcmpnent r getcmpnent 10 5

11 Cmpsite pattern Intent Cmpse bjects int tree structures t represent part-whle hierarchies. Cmpsite lets clients treat individual bjects and cmpsitins f bjects unifrmly. This is called recursive cmpsitin Applicability Yu want t represent part-whle hierarchies f bjects Yu want clients t be able t ignre the difference between cmpsitins f bjects and individual bjects. Clients will treat all bjects in the cmpsite structure unifrmly. 12 6

Cmpsite Pattern UML 13 Cmpsite Pattern UML - Participants Cmpnent declares the interface fr bjects in the cmpsitin. implements default behavir fr the interface cmmn t all classes, as apprpriate. declares an interface fr accessing and managing its child cmpnents. Leaf (ptinal) defines an interface fr accessing a cmpnent's parent in the recursive structure, and implements it if that's apprpriate. represents leaf bjects in the cmpsitin. A leaf has n children. defines behavir fr primitive bjects in the cmpsitin. 14 7

Cmpsite Pattern UML - Participants Cmpsite defines behavir fr cmpnents having children. stres child cmpnents. implements child-related peratins in the Cmpnent interface. Client manipulates bjects in the cmpsitin thrugh the Cmpnent interface. 15 Cmpsite Pattern Real wrld example Java Use f Cmpsite - AWT Widgets 16 8

Cllectinal Patterns Iteratr Pattern 17 Iteratr Pattern Descriptin The Iteratr pattern allws a client bject t access the cntents f a cntainer in a sequential manner, withut having any knwledge abut the internal representatin f its cntents. The term cntainer can simply be defined as a cllectin f data r bjects. The Iteratr pattern enables a client bject t traverse thrugh this cllectin f bjects (r the cntainer) withut having the cntainer t reveal hw the data is stred internally. The Cntainer bject shuld be designed t prvide a public interface in the frm f an Iteratr bject fr different client bjects t access its cntents. 18 9

Iteratr Pattern UML 19 Iteratr Pattern UML - Participants Iteratr (AbstractIteratr) defines an interface fr accessing and traversing elements. CncreteIteratr (Iteratr) implements the Iteratr interface. keeps track f the current psitin in the traversal f the aggregate. Aggregate (AbstractCllectin) defines an interface fr creating an Iteratr bject CncreteAggregate (Cllectin) implements the Iteratr creatin interface t return an instance f the prper CncreteIteratr 20 10

Types f Iteratr Internal iteratrs The cllectin itself ffers methds t allw a client t visit different bjects within the cllectin. Fr example, the java.util.resultset class cntains the data and als ffers methds such as next() t navigate thrugh the item list There can be nly ne iteratr n a cllectin at any given time The cllectin has t maintain r save the state f iteratin. 21 Types f Iteratr External iteratrs The iteratin functinality is separated frm the cllectin and kept inside a different bject referred t as an iteratr. Usually, the cllectin itself returns an apprpriate iteratr bject t the client depending n the client input. There can be multiple iteratrs n a given cllectin at any given time. The verhead invlved in string the state f iteratin is nt assciated with the cllectin. It lies with the exclusive Iteratr bject. 22 11

Iteratr Pattern Internal Iteratr example 23 Iteratr Pattern External Iteratr example 24 12

Iteratr Pattern Real wrld Java Example DOM Traversal Example 25 Summary Pattern Name Cm psite Iteratr Fly weight Visitr Descriptin Allws bth individual bjects and cm psite bjects t be treated unifrmly. Allws a client t access the cntents f an aggregate bject (cllectin f bjects) in sme sequential manner, withut having any knwledge abut the internal representatin f its cntents. The intrinsic, invariant cmmn infrmatin and the variable parts f a class are separated int tw classes, leading t savings in terms f the memry usage and the amunt f time required fr the creatin f a large number f its instances. Allws an peratin t be defined acrss a cllectin f different bjects withut changing the classes f bjects n which it perates. 26 13

Questins and Answers 27 14