PQL Programming using Object
Download
Report
Transcript PQL Programming using Object
PQL Programming using ObjectOriented Methods
Randy Banks ([email protected])
ISER, University of Essex
http://www.iser.essex.ac.uk
Outline
• What is Object-Oriented Design (OOD)?
• OOD concepts and tools - Unified Modelling
Language (UML)
• OOD & SIR/PQL
• Real-life example – SIR/SDSX
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
What is OOD?
• OOD is conceptual modelling technique (like EntityRelationship 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
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
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
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
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
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
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 …
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
me:
kage:
sion:
hor:
OOD/UML Example - Conference Refreshment System - Class Diagram
Classes
1.0
Randy Banks
OOD Example. Conference Drinks - Classes
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.
«enumeration»
ageTypes
Attendee
+
#
-
name: string
country: string
age: ageTypes
attendeeType: attendeeTypes
+
isDelegate() : boolean
+
+
UML 'stereotypes' (traditionally surrounded by
guillemot characters (<< .. >>) can te attached to any
UML element to provide additional information that
extends the basic UML semantics.
adult:
child:
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
«enumeration»
attendeeTypes
responsibilities
manage SUG conference attendees
+
+
+
delegate:
partner:
child:
Refreshment
Order
+
+
supporter: Supporter
refreshment: Refreshment [1..*]
+
+
orderDrink(refreshmentId :string) : currency
orderTotal() : currency
Supporter
-
wallet: currency
-
+places
canDrink() : boolean
updateWallet(orderCost :currency) : void 0..*
+satisfies
+requires
1..*
responsibilities
1..* manage drink orders
responsibilities
manage drinkers
+confirms
availability
1..*
+
+
+
+
name: string
nInStock: int
price: currency
id: string
-
updateStock(nInOut :int) : int
responsibilities
drinks control
1..*
+gets
Summary
+
totalCost() : currency
responsibilities
determine total damage to wealth (and health?)
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
Properties have
multiplicity has well ...
an order might include
one or more drinks
Name:
Package:
Version:
Author:
OOD/UML Example - Conference Refreshment System - Object Diagram
Objects
1.0
Randy Banks
OOD Example. Conference Drinks - Objects
champagne
(bottle) :
Refreshment
In UML diagrams,
object names are
underlined and take
the form: [object]:class
mo :Attendee
mo :Supporter
clynelish (large) :
Refreshment
moOrder1 :Order
champagne
(magnum) :
Refreshment
Attributes of
associations are
suppressed as they are
provided by the
corresponding class
diagram.
dav ed :Attendee
dav ed :
Supporter
pernod (large) :
Refreshment
bitter (pint) :
Refreshment
ddOrder1 :Order
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
cider (half) :
Refreshment
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 …
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
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. …
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 SUBROUTINE
END PROCEDURE
PROCEDURE CHILD.COMPILE
CALL PARENT.INHERIT(CHILD)
more child subroutines, etc
END PROCEDURE
CALL CHILD.COMPILE
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’
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’
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
Name:
Package:
Version:
Author:
SDSX - database and associated Elements
Database
1.0
Randy Banks
SDSX. Specification
SDSX::sdsx
responsibilities
root element
0..*
database
«PCDATA»
Anyw here::extend
+
+
+
+
+
+
name: string
value: string [0..1]
name: string
«ID» id: string [0..1]
dbms: dbmsTypes [0..1]
dbmsver: string [0..1]
0..*
responsibilities
semantic extensions
responsibilities
database structure
1..*
«PCDATA»
Anyw here::comment
+
+
«ID» id: string [0..1]
«IDREF» libid: string [0..1]
0..1
responsibilities
COMMENT (DOCUMENT) info
idv ar
record
0..1
+
+
+
name: string
recno: integer [0..1]
«ID» id: string [0..1]
responsibilities
record (table) info
0..1
+
+identifies +
+
1..* +
name: string
order: integer
«ID» id: string [0..1]
«IDREF» varid: string [0..1]
responsibilities
PRIMARY KEY (CASEID and/or KEY VAR) info
0..1
1..*
«PCDATA»
Anyw here::label
+
+
+
«ID» id: string [0..1]
type: labelTypes [0..1]
«IDREF» libid: string [0..1] 0..1
responsibilities
element label
v ariable
+
+
+
«ID» id: string [0..1]
name: string
type: varTypes [0..1]
responsibilities
COLUMN (VARIABLE) info
«enumeration»
v arTypes
+
+
+
+
+
+
char:
int:
single:
double:
date:
time:
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
SIR/SDSX. User Interface
«global vars»
Globals
+
+
+
+
+
+
sdxfil: string = sdsx.xml
sdxdb: string
sdxpfx: string
sdxpwd: string
sdxrs: string
sdxws: string
«boundary»
SDSX
+
General::XML
responsibilities
XML tag generation
Database::Database
«procedure» sdsx(string, string, string, string, string, string) : void
responsibilities
responsibilities
gets DATABASE level data
user interface
General::PQL
'PQL' class is from
'General' package
responsibilities
generic PQL methods
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
Version:
Author:
1.0
Randy Banks
SIR/SDSX. Database Package
General::XML
responsibilities
XML tag generation
Anyw here::Comment
responsibilities
generate comment info (from DOCUMENt/long VARLAB)
Anyw here::Extend
Database
responsibilities
gets DATABASE level data
database tag includes
dbms='sirdbms'
dbmsver='<sirver>'
responsibilities
extends SDSX semantics
Record::Record
responsibilities
gets RECTYPE level data
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
database level
extend tags include:
<extend
name='type'
value='case|
caseless' />
SDSX. Record Package
Anyw here::Comment
General::XML
responsibilities
generate comment info (from DOCUMENt/long VARLAB)
responsibilities
XML tag generation
Record
IDVar
responsibilities
gets RECTYPE level data
responsibilities
get ID variable information
Variable::Variable
responsibilities
gets VARIABLE level data
General::PQL
responsibilities
generic PQL methods
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
Package: Variable
Version: 1.0
Author:
Randy Banks
SIR/SDSX. Variable Package
General::Error
Anyw here::Comment
responsibilities
information/error handling
responsibilities
generate comment info (from DOCUMENt/long VARLAB)
Variable
responsibilities
gets VARIABLE level data
General::XML
Anyw here::Label
responsibilities
XML tag generation
responsibilities
get var/value labels
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
SIR/SDSX. Anywhere Package
Extend
responsibilities
extends SDSX semantics
Comment
responsibilities
generate comment info (from DOCUMENt/long VARLAB)
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
Label
responsibilities
get var/value labels
Version:
Author:
1.0
Randy Banks
SIR/SDSX. General Package
Obj ect
IO
Error
responsibilities
file I/O handling
responsibilities
information/error handling
XML
«global vars»
XML::Globals
+
-
indlevel: integer = 0
indsize: integer = 2
xmlindnt: integer
responsibilities
XML tag generation
XMLIO
responsibilities
handles IO for XML class
PQL
UTF8
responsibilities
generic PQL methods
responsibilities
utf-8 encoding
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)
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
See also, for …
•
OOD, OO Methodology, UML
–
–
–
–
–
–
–
–
•
UML Tools
–
–
–
•
Home Page (http://www.icpsr.umich.edu/DDI/)
General Information
–
–
–
•
http://www.google.*
W3C (http://www.w3.org/XML/)
W3 Schools XML tutorial (http://www.w3schools.com/xml/)
Ray. Learning XML
Data Documentation Initiative
–
•
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.*
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
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/)
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.
That’s all
• folks
PQL Programming using Object-Oriented Methods.
SIR Users Group Conference, June 28-30, 2006, Stratford.