Docstoc

PQL Programming using Object-Oriented Methods

Document Sample
PQL Programming using Object-Oriented Methods Powered By Docstoc
					PQL Programming using Object-
      Oriented Methods


     Randy Banks (randy@essex.ac.uk)
         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 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

                  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:      OOD/UML Example - Conference Refreshment System - Class Diagram
 kage:   Classes
sion:    1.0
hor:     Randy Banks


              OOD Example. Conference Drinks - Classes
                                                      Attendee                                  «enumeration»
         UML class symbols are                                                                    ageTypes                          UML 'stereotypes' (traditionally surrounded by
         divided into horisontal         +   name: string                                                                           guillemot characters (<< .. >>) can te attached to any
         sections (attributes,           -   country: string                                   +    adult:                          UML element to provide additional information that
         then operations, then           #   age: ageTypes                                     +    child:                          extends the basic UML semantics.
         other things such as            -   attendeeType: attendeeTypes
         requirements) which                                                                                                        The <<enumeration>> stereotype applied to the
         may or may not be                                                                         «enumeration»
                                         +   isDelegate() : boolean                                                                 AgeTypes and attendeeTypes classes indicate that
         displayed.                                                                                attendeeTypes
                                                                                                                                    their attributes are simply a list of valid values for the
                                                responsibilities                                +    delegate:                      attributes in some other class, in this case, Attendees
         A '+' before an                 manage SUG conference attendees                        +    partner:
         attribute or operation                                                                 +    child:
         indicates that it is
         'public'; a '-' that it is
         private; a '#' that it is
         protected.

                                                                                                               Order                                                                 Refreshment

                                                                                       +    supporter: Supporter                                                           +   name: string
                                                                                                                                                        +confirms          +   nInStock: int
                                                                                       +    refreshment: Refreshment [1..*]
                                                                                                                                           +requires    availability       +   price: currency
                             Supporter
                                                                                       +    orderDrink(refreshmentId :string) : currency                                   +   id: string
                                                                                                                                           1..*                     1..*
         -   wallet: currency                                                          +    orderTotal() : currency
                                                      +places         +satisfies                                                                                           -   updateStock(nInOut :int) : int
         -   canDrink() : boolean                                                              responsibilities
         -   updateWallet(orderCost :currency) : void 0..*                  1..* manage drink orders                                                                                responsibilities
                                                                                                                                                                           drinks control
                     responsibilities                                                                                1..*
         manage drinkers
                                                                                                             +gets

                                                                                                             Summary                                             Properties have
                                                                                                                                                                 multiplicity has well ...
                                                                                   +       totalCost() : currency                                                an order might include
                                                                                                                                                                 one or more drinks
                                                                                                   responsibilities
                                                                                   determine total damage to wealth (and health?)



                                                          PQL Programming using Object-Oriented Methods.
                                                          SIR Users Group Conference, June 28-30, 2006, Stratford.
Name:      OOD/UML Example - Conference Refreshment System - Object Diagram
Package:   Objects
Version:   1.0
OOD Example. Conference Drinks - Objects
Author:    Randy Banks



                                                                                           champagne
                  In UML diagrams,                                                           (bottle) :
                  object names are                                                         Refreshment
                  underlined and take
                  the form: [object]:class                                               clynelish (large) :
                                                                                           Refreshment



            mo :Attendee               mo :Supporter          moOrder1 :Order             pernod (large) :
                                                                                           Refreshment



                                                                                           champagne
                                                                                            (magnum) :
                   Attributes of                                                           Refreshment
                   associations are
                   suppressed as they are                                                  bitter (pint) :
                   provided by the                                                         Refreshment
                   corresponding class
                   diagram.



           dav ed :Attendee               dav ed :            ddOrder1 :Order              cider (half) :
                                         Supporter                                         Refreshment



                              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 …


                  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:      SDSX - database and associated Elements
Package:   Database
Version:   1.0
Author:

                SDSX. Specification
           Randy Banks




                                                                 SDSX::sdsx


                                                               responsibilities
                                                               root element




                                                                        0..*

                                                                   database
                   «PCDATA»
                Anyw here::extend                +       name: string
                                                 +       «ID» id: string [0..1]
            +    name: string
                                                 +       dbms: dbmsTypes [0..1]
            +    value: string [0..1]            +       dbmsver: string [0..1]
                                          0..*
              responsibilities                          responsibilities
            semantic extensions                  database structure




                                                                         1..*
                                                                                                                        idv ar
           «PCDATA»                     0..1                        record
       Anyw here::comment                                                                          +   name: string
                                                     +       name: string
                                                                                       +identifies +   order: integer
   +   «ID» id: string [0..1]                        +       recno: integer [0..1]                 +   «ID» id: string [0..1]
   +   «IDREF» libid: string [0..1]       0..1       +       «ID» id: string [0..1]           1..* +   «IDREF» varid: string [0..1]

       responsibilities                                    responsibilities                                  responsibilities
   COMMENT (DOCUMENT) info                           record (table) info                          PRIMARY KEY (CASEID and/or KEY VAR) info
                                         0..1

                                                                                                       0..1

                                                                          1..*

                   «PCDATA»                                                                        «enumeration»
                                                                   v ariable                         v arTypes
                 Anyw here::label
                                                         +    «ID» id: string [0..1]              +    char:
       +   «ID» id: string [0..1]
                                                         +    name: string                        +    int:
       +   type: labelTypes [0..1]
                                                         +    type: varTypes [0..1]               +    single:
       +   «IDREF» libid: string [0..1] 0..1
                                                                                                  +    double:
                                                            responsibilities                      +    date:
             responsibilities
                                                         COLUMN (VARIABLE) info                   +    time:
       element label



                           PQL Programming using Object-Oriented Methods.
                           SIR Users Group Conference, June 28-30, 2006, Stratford.
SIR/SDSX. User Interface
                              «global vars»
                                Globals
                                                                                    General::XML
                      +   sdxfil: string = sdsx.xml
                      +   sdxdb: string
                      +   sdxpfx: string                                          responsibilities
                      +   sdxpwd: string                                       XML tag generation
                      +   sdxrs: string
                      +   sdxws: string




                               «boundary»
                                 SDSX                                            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:   1.0
Author:    Randy Banks




                 SIR/SDSX. Database Package
                              General::XML                                        Anyw here::Comment


                             responsibilities                                      responsibilities
                          XML tag generation                      generate comment info (from DOCUMENt/long VARLAB)




                                                                      Anyw here::Extend                database level
                                Database                                                               extend tags include:

                                                                       responsibilities                <extend
                              responsibilities
                                                                  extends SDSX semantics               name='type'
                         gets DATABASE level data
                                                                                                       value='case|
                                                                                                       caseless' />




                                                                        Record::Record
                          database tag includes
                          dbms='sirdbms'
                          dbmsver='<sirver>'                            responsibilities
                                                                   gets RECTYPE level data




                                            PQL Programming using Object-Oriented Methods.
                                            SIR Users Group Conference, June 28-30, 2006, Stratford.
SDSX. Record Package
                Anyw here::Comment

                                                                  General::XML
                 responsibilities
generate comment info (from DOCUMENt/long VARLAB)
                                                                 responsibilities
                                                              XML tag generation




       Record                                                            IDVar


    responsibilities                                              responsibilities
gets RECTYPE level data                                      get ID variable information




   Variable::Variable
                                                                      General::PQL

     responsibilities
                                                                  responsibilities
gets VARIABLE level data
                                                                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                                    responsibilities
                information/error handling              generate comment info (from DOCUMENt/long VARLAB)




                          Variable


                     responsibilities
                gets VARIABLE level data

                                                                          General::XML


                                                                        responsibilities
                   Anyw here::Label                                  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                                      Comment                               Label


     responsibilities                       responsibilities                         responsibilities
extends SDSX semantics     generate comment info (from DOCUMENt/long VARLAB)        get var/value labels




                         PQL Programming using Object-Oriented Methods.
                         SIR Users Group Conference, June 28-30, 2006, Stratford.
Version:    1.0
Author:     Randy Banks



                  SIR/SDSX. General Package
                                         Obj ect                            IO                        Error


                                                                      responsibilities            responsibilities
                                                                     file I/O handling       information/error handling



                                           XML
           «global vars»                                                  XMLIO
           XML::Globals        -     indlevel: integer = 0
                               -     indsize: integer = 2
     +     xmlindnt: integer                                         responsibilities
                                  responsibilities                handles IO for XML class
                               XML tag generation




                                           PQL                             UTF8


                                     responsibilities                responsibilities
                                   generic PQL methods               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
     –    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/)


                                   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.

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:5
posted:4/7/2010
language:English
pages:27