pql programming using object- oriented methods randy banks ([email protected])[email protected]...

27
PQL Programming using Object-Oriented Methods Randy Banks ([email protected] ) ISER, University of Essex http://www.iser.essex.ac.uk

Upload: curtis-randles

Post on 01-Apr-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods

Randy Banks ([email protected])

ISER, University of Essex

http://www.iser.essex.ac.uk

Page 2: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Outline

• What is Object-Oriented Design (OOD)?

• OOD concepts and tools - Unified Modelling Language (UML)

• OOD & SIR/PQL

• Real-life example – SIR/SDSX

Page 3: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

What is OOD?• OOD is conceptual modelling technique (like Entity-

Relationship Modelling (ERM))

• ERM is for database design

• OOD is for just about anything– Abstract, generalisable, thus applicable to extremely wide range

of software engineering problems

– ERM on steroids … and 10 fruit portions a day

• OOD helps build code that is– Reliable

– Reusable

– Maintainable

– Robust

Page 4: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

How does it work?

• OOD decomposes universe of discourse into classes, objects and associations between them

• Classes are ‘templates’ for the creation of objects

• Objects are ‘instantiations’ of a class

• Associations relate classes/objects to each other

Page 5: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Classes/Objects

• May have properties (attributes) and/or methods (operations)

• Properties store information about an object, e.g. variables

• Methods accomplish tasks, e.g. functions

• Packages used to organise and group related classes and provide contained namespace

Page 6: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Methods and Properties

• Scope is local to class in which defined

– impact of change can be controlled

• Access by other methods (of other classes) may be more or less restricted

– Private - available only to methods of same class

– Protected - available to methods of same and ‘child’ (later) classes

– Public - available to method in any class

Page 7: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Types of Associations• Bog-standard (untyped)

• Dependency (very weak)

• Aggregation (objects of one class are ‘part of’ objects of another)

• Composition (objects of one class are ‘made up of objects of another)

• Inheritance (objects of one class (the ‘child’) share the properties and methods of another (the ‘parent’)

– ‘is-a’ relationships

Page 8: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Properties of Associations

• Roles

– Indicates what the association, and the associated elements, do

• Direction

– Defines which way information/messages flow between objects of one class and objects of another

• Multiplicity (cardinality)

– Specifies how many objects of one class are related to objects of another

Page 9: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Unified Modelling Language (UML)

• Standard

– To support OOD

– Maintained by Object Management Group (OMG)

• (ultimate goal is to) Provide concepts and diagrams to cover all aspects of the development process

– from user requirements to on-going maintenance

• The Microsoft {SAS,IBM} of Modelling

• For example …

Page 10: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD Example. Conference Drinks - Classes

cd OOD/UML Example - Conference Refreshment System - Class Diagram

Attendee

+ name: string- country: string# age: ageTypes- attendeeType: attendeeTypes

+ isDelegate() : boolean

responsibilitiesmanage SUG conference attendees

Supporter

- wallet: currency

- canDrink() : boolean- updateWallet(orderCost :currency) : void

responsibilitiesmanage drinkers

Refreshment

+ name: string+ nInStock: int+ price: currency+ id: string

- updateStock(nInOut :int) : int

responsibilitiesdrinks control

Order

+ supporter: Supporter+ refreshment: Refreshment [1..*]

+ orderDrink(refreshmentId :string) : currency+ orderTotal() : currency

responsibilitiesmanage drink orders

Summary

+ totalCost() : currency

responsibilitiesdetermine total damage to wealth (and health?)

«enumeration»ageTypes

+ adult: + child:

«enumeration»attendeeTypes

+ delegate: + partner: + child:

UML 'stereotypes' (traditionally surrounded by guillemot characters (<< .. >>) can te attached to any UML element to provide additional information that extends the basic UML semantics.

The <<enumeration>> stereotype applied to the AgeTypes and attendeeTypes classes indicate that their attributes are simply a list of valid values for the attributes in some other class, in this case, Attendees

UML class symbols are divided into horisontal sections (attributes, then operations, then other things such as requirements) which may or may not be displayed.

A '+' before an attribute or operation indicates that it is 'public'; a '-' that it is private; a '#' that it is protected.

Properties have multiplicity has well ... an order might include one or more drinks

+gets

1..*

+requires

1..*

+confirmsavailability

1..*

+places

0..*

+satisfies

1..*

Name:Package:Version:Author:

OOD/UML Example - Conference Refreshment System - Class DiagramClasses1.0Randy Banks

Page 11: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD Example. Conference Drinks - Objects

cd OOD/UML Example - Conference Refreshment System - Object Diagram

mo :Attendee mo :Supporter moOrder1 :Order

champagne (bottle) :

Refreshment

clynelish (large) :Refreshment

pernod (large) :Refreshment

champagne (magnum) :

Refreshment

bitter (pint) :Refreshment

dav ed :Attendee dav ed :Supporter

ddOrder1 :Order cider (half) :Refreshment

In UML diagrams, object names are underlined and take the form: [object]:class

Attributes of associations are suppressed as they are provided by the corresponding class diagram.

Name:Package:Version:Author:

OOD/UML Example - Conference Refreshment System - Object DiagramObjects1.0Randy Banks

Page 12: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Object-Oriented Programming Languages (OOPLs)

• OOPLs more or less implement OOD concepts

– of which there are many more than described above

• Many benefits to OOPLs

– ‘code control’

• PQL is not an OOPL

• OOD concepts can be mapped on to PQL

• OOD methods can be used to design PQL applications

• here’s one I made earlier …

Page 13: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD & SIR/PQL. Classes• Classes can be implemented as PQL procedure

Families– As PQL is not an OOPL, no distinction between

classes and objects

• Methods can be implemented as PQL Subroutines– Procedures, too, but no localisation

– alas, no functions

• Properties can be implemented as PQL External Variable Blocks

Page 14: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD & SIR/PQL. Associations

• Nothing in PQL to implement associations

• Associations are realised by executing subroutines

– or calling procedures

• Can realise inheritance by defining family name of a subroutine at compile time

• E.G. …

Page 15: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD & PQL. Inheritance

PROCEDURE PARENT.INHERIT SUBROUTINE <1>.METHOD pql code … END SUBROUTINEEND PROCEDURE

PROCEDURE CHILD.COMPILE CALL PARENT.INHERIT(CHILD) more child subroutines, etcEND PROCEDURE

CALL CHILD.COMPILE

Page 16: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

OOD & PQL. Inheritance Qualification

• Use above technique judiciously

– No protection of inherited methods … get all or nothing …

– … which may conflict with methods specific to child ‘class’

Page 17: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

A Real-life Example. SIR/SDSX• Problem

– Generic, software-independent means of storing/transferring survey metadata, including SIR/DBMS schema information

• Solution– SDSX (Survey Delivery System Exchange Format or Survey

Delivery System XML Transfer Format or … whatever …)• Similar objectives to DDI (Data Documentation Initiative• XML format

• SIR/SDSX– Application to write database schema information into SDSX

format

• SDSX and SIR/SDSX are ‘in progress’

Page 18: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SDSX. Specification

cd SDSX - database and associated Elements

database

+ name: string+ «ID» id: string [0..1]+ dbms: dbmsTypes [0..1]+ dbmsver: string [0..1]

responsibilitiesdatabase structure

v ariable

+ «ID» id: string [0..1]+ name: string+ type: varTypes [0..1]

responsibilitiesCOLUMN (VARIABLE) info

record

+ name: string+ recno: integer [0..1]+ «ID» id: string [0..1]

responsibilitiesrecord (table) info

idv ar

+ name: string+ order: integer+ «ID» id: string [0..1]+ «IDREF» varid: string [0..1]

responsibilitiesPRIMARY KEY (CASEID and/or KEY VAR) info

«enumeration»v arTypes

+ char: + int: + single: + double: + date: + time:

SDSX::sdsx

responsibilitiesroot element

«PCDATA»Anywhere::comment

+ «ID» id: string [0..1]+ «IDREF» libid: string [0..1]

responsibilitiesCOMMENT (DOCUMENT) info

«PCDATA»Anywhere::label

+ «ID» id: string [0..1]+ type: labelTypes [0..1]+ «IDREF» libid: string [0..1]

responsibilitieselement label

«PCDATA»Anywhere::extend

+ name: string+ value: string [0..1]

responsibilitiessemantic extensions

0..*

0..*

1..*

1..*

0..1

+identifies

1..*0..1

0..1

0..1

0..1

Name:Package:Version:Author:

SDSX - database and associated ElementsDatabase1.0Randy Banks

Page 19: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SIR/SDSX. User Interface

cd SIR/SDSX - User Interface and Associated Families

«boundary»SDSX

+ «procedure» sdsx(string, string, string, string, string, string) : void

responsibilitiesuser interface

«global vars»Globals

+ sdxfil: string = sdsx.xml+ sdxdb: string+ sdxpfx: string+ sdxpwd: string+ sdxrs: string+ sdxws: string

General::PQL

responsibilitiesgeneric PQL methods

Database::Database

responsibilitiesgets DATABASE level data

General::XML

responsibilitiesXML tag generation

'PQL' class is from 'General' package

Name:Package:Version:Author:

SIR/SDSX - User Interface and Associated FamiliesSIR/SDSX1.0Randy Banks

Page 20: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SIR/SDSX. Database Package

cd SIR/SDSX - Database and Related Families

Database

responsibilitiesgets DATABASE level data

General::XML

responsibilitiesXML tag generation

Anywhere::Extend

responsibilitiesextends SDSX semantics

Record::Record

responsibilitiesgets RECTYPE level data

Anywhere::Comment

responsibilitiesgenerate comment info (from DOCUMENt/long VARLAB)

database level extend tags include:

<extend name='type' value='case| caseless' />

database tag includes dbms='sirdbms' dbmsver='<sirver>'

Name:Package:Version:Author:

SIR/SDSX - Database and Related FamiliesDatabase1.0Randy Banks

Page 21: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SDSX. Record Package

cd SIR/SDSX - Record and Associated Families

Record

responsibilitiesgets RECTYPE level data

General::XML

responsibilitiesXML tag generation

IDVar

responsibilitiesget ID variable information

Variable::Variable

responsibilitiesgets VARIABLE level data

Anywhere::Comment

responsibilitiesgenerate comment info (from DOCUMENt/long VARLAB)

General::PQL

responsibilitiesgeneric PQL methods

Name:Package:Version:Author:

SIR/SDSX - Record and Associated FamiliesRecord1.0Randy Banks

Page 22: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SIR/SDSX. Variable Package

cd SIR/SDSX - Variable and Related Families

Variable

responsibilitiesgets VARIABLE level data

Anywhere::Comment

responsibilitiesgenerate comment info (from DOCUMENt/long VARLAB)

General::Error

responsibilitiesinformation/error handling

General::XML

responsibilitiesXML tag generationAnywhere::Label

responsibilitiesget var/value labels

Name:Package:Version:Author:

SIR/SDSX - Variable and Related FamiliesVariable1.0Randy Banks

Page 23: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SIR/SDSX. Anywhere Package

cd SIR/SDSX - Families That Can be Used by Any Other SIR/SDSX Families

Label

responsibilitiesget var/value labels

Comment

responsibilitiesgenerate comment info (from DOCUMENt/long VARLAB)

Extend

responsibilitiesextends SDSX semantics

Name:Package:Version:Author:

SIR/SDSX - Families That Can be Used by Any Other SIR/SDSX FamiliesAnywhere1.0Randy Banks

Page 24: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

SIR/SDSX. General Package

cd SIR/PQL - General Purpose Families

Error

responsibilitiesinformation/error handling

IO

responsibilitiesfi le I/O handling

Object

PQL

responsibilitiesgeneric PQL methods

UTF8

responsibilitiesutf-8 encoding

«global vars»XML::Globals

+ xmlindnt: integer

XML

- indlevel: integer = 0- indsize: integer = 2

responsibilitiesXML tag generation

XMLIO

responsibilitieshandles IO for XML class

Name:Package:Version:Author:

SIR/PQL - General Purpose FamiliesGeneral1.0Randy Banks

Page 25: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

Summary• OOD provides general purpose methods to solve a

variety of software engineering problems

• Very popular – lots of information, methodologies & tools

• Even though PQL is not an OOPL, OOD can be applied to PQL applications development

• Value of approach can only be judged by results

– More work at the design stage, less hassle later

– Effectiveness depends on how applied ... art and science (methodology) are both necessary (cf. Clausewitz, On War; Tolstoy, War and Peace)

Page 26: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

See also, for …• OOD, OO Methodology, UML

– http://www.google.*– Agile Modeling (http://www.agilemodeling.com/)– Object Management Group (http://www.uml.org/)– a nice glossary of OO terms (http://www.microgold.com/version2/stage/tutorial/glossary.html)– Journal of Object Technology (http://www.microgold.com/version2/stage/tutorial/glossary.html)– UML resources from SparxSystems (http://www.sparxsystems.com.au/resources/)– Bruegge & Dutoit. Object-Oriented Software Engineering– Alhir. Learning UML

• UML Tools– http://www.google.*– Enterprise Architect (http://www.sparxsystems.com.au/) – my favourite; excellent value for ££– Poseidon (http://gentleware.com/index.php) – ‘Community Edition’ is free

• XML– http://www.google.*– W3C (http://www.w3.org/XML/)– W3 Schools XML tutorial (http://www.w3schools.com/xml/)– Ray. Learning XML

• Data Documentation Initiative– Home Page (http://www.icpsr.umich.edu/DDI/)

• General Information– W3 Schools (http://www.w3schools.com/)– Tolstoy. War and Peace– Clausewitz. On War

• Sheer entertainment value– NTK (http://www.ntk.net/)– World Wide Words (http://www.worldwidewords.org/)

Page 27: PQL Programming using Object- Oriented Methods Randy Banks (randy@essex.ac.uk)randy@essex.ac.uk ISER, University of Essex

PQL Programming using Object-Oriented Methods.SIR Users Group Conference, June 28-30, 2006, Stratford.

That’s all

• folks