Top Banner
OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming
36

OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

Dec 17, 2015

Download

Documents

Juniper Floyd
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM

Martin PhillipsLadybridge Systems Ltd

Object Oriented Programming

Page 2: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMWhat’s it all about?

What is an object?

Persistent data

Public subroutines and functions

Inheritance

Destructors and undefined name handlers

Page 3: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMWhat’s It All About?

OO programming does not replace “conventional” methods.

A new addition to the developer’s toolbox.

An integral part of the QMBasic language.

Page 4: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMWhat Is An Object?

Subroutine:Program operations that work on supplied data.

Object:Data that has associated program operations.

Page 5: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMWhat Is An Object?

Defined by a CLASS module.

The CLASS module is a container for...

• The persistent data definitions.

• The program operations that run against this data.

Page 6: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMWhat Is An Object?

An object is a run time instance of the class.

var = OBJECT(“myobj.cls”)

There may be many concurrent instances of the same class each with their own data.

Page 7: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMThe Objref Operator ( -> )

References an element of the object.

var->name

var->(expr)

Page 8: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPersistent Data

Class modules may use common blocks but these are shared across all instances of the class.

Class modules also have persistent data that is separate for each instance.

Page 9: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPersistent Data

Private data...

-Not visible outside the class module.

-Hides internal operation of the object.

PRIVATE A, B, C(2,3)

Page 10: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPersistent Data

Public data...

-May be visible to programs using the object.

PUBLIC P, Q, R(2,3)

PUBLIC X READONLY

Page 11: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPersistent Data

Referenced from calling program:

result = var->item

var->item = 12

var->item(3) = 12

Page 12: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

Program operations contained within the class module.

May access or update persistent data.

Public subroutines store values or perform tasks.

Public functions return a result value.

Page 13: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

PUBLIC SUBROUTINE name ... Program operations ...END

var->name

Page 14: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

PUBLIC SUBROUTINE name(a,b) ... Program operations ...END

var->name(x,y)

var->name(x) = y

Page 15: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

PUBLIC FUNCTION name(a,b) ... Program operations ... RETURN valueEND

p = var->name(q, r)

Page 16: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

Variable length named argument lists...

PUBLIC FUNCTION name(a,b) VAR.ARGS ... Program operations ... RETURN valueEND

Page 17: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

Variable length unnamed argument lists...

PUBLIC FUNCTION name(a, ...) ... Program operations ... RETURN valueEND

Page 18: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMPublic Subroutines and Functions

Access arguments by position...

ARG.COUNT()

ARG(n)

SET.ARG n, value

Page 19: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMDual Identity

A name may refer to a public data item when reading and program operations when writing...

...Or vice versa

Allows easy data validation or event triggers.

Page 20: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMInheritance

One class may want to use the data and public routines of another.

The inherited class remains a “black box” where the outer class cannot see how it works.

Page 21: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMInheritance

Static Inheritance...

CLASS name INHERITS other.class

Page 22: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMInheritance

Dynamic Inheritance...

obj = object(“otherclass”)INHERIT obj

Page 23: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMInheritance

Dis-inheritance...

DISINHERIT obj

Page 24: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM“Automatic” Handlers

CREATE.OBJECT

DESTROY.OBJECT

UNDEFINED (Subroutine / Function)

Page 25: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM“Automatic” Handlers

CREATE.OBJECT

Run when the object is instantiated.

Arguments to OBJECT() are passed to this subroutine.

Page 26: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM“Automatic” Handlers

DESTROY.OBJECT

Run when the last variable referencing the object is released.

Guaranteed execution, even at program abort.

Page 27: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM“Automatic” Handlers

UNDEFINED

Run for references to undefined names.

Both FUNCTION and SUBROUTINE can exist.

Caller’s arguments passed, plus name.

Page 28: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMExample Class Module

This example will walk through a directory, returning the name and type of each item.

Page 29: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMStep 1 – Data Definitions

CLASS DIR.CLS$CATALOGUE PRIVATE ENTRIES ;* From DIR() PUBLIC ISDIR READONLYEND

Page 30: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMStep 2 – CREATE.OBJECT

PUBLIC SUBROUTINE CREATE.OBJECT(P) ENTRIES = DIR(P)END

Page 31: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMStep 3 – Retrieve the next item name

PUBLIC FUNCTION NEXT NAME = ENTRIES<1,1> ISDIR = (ENTRIES<1,2> = 'D') DEL ENTRIES<1> RETURN NAMEEND

Page 32: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

CLASS DIR.CLS$CATALOGUE PRIVATE ENTRIES ;* From DIR() PUBLIC ISDIR READONLY ;* Is a directory?

PUBLIC SUBROUTINE CREATE.OBJECT(PATH) ENTRIES = DIR(PATH) END

PUBLIC FUNCTION NEXT NAME = ENTRIES<1,1> ISDIR = (ENTRIES<1,2> = 'D') DEL ENTRIES<1> RETURN NAME ENDEND

Page 33: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQMUsing the Class

DIR = OBJECT('DIR.CLS', '\TEMP')LOOP NAME = DIR->NEXTUNTIL NAME = '' DISPLAY NAMEREPEAT

Page 34: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

PROGRAM OBJECT.DEMO GOSUB SCAN(0, '\QMSYS') STOP

LOCAL SUBROUTINE SCAN(INDENT, PATH) PRIVATE DIR

DIR = OBJECT('DIR.CLS', PATH) LOOP NAME = DIR->NEXT UNTIL NAME = '' CRT SPACE(INDENT) : NAME IF DIR->ISDIR THEN GOSUB SCAN(INDENT + 3, PATH:'\'NAME) END REPEAT

RETURN ENDEND

Page 35: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM

QUESTIONS?

Page 36: OpenQM Martin Phillips Ladybridge Systems Ltd Object Oriented Programming.

OpenQM