[comp.lang.pascal] Turbo Pascal OOP

OXC@psuvm.psu.edu (10/02/90)

>I'm interested in Virtual and dynamic topics with complete coverage.  I'm
>new to OOP and would like some help wadeing through the Objects unit supplied
>with TP 5.5!  Any personal experience and/or knowledge of pitfalls, etc.
>would be welcome.   ...

I have recently spent some time with Object-Oriented Programming Turbo 5.5
style.  Here are some of my experiences.

In retrospect, my first exposure to OOP concepts which involved how
different vehicles stop, is not a bad way explain polymorphism, but at the
time, I felt sidetracked by this and similar examples.  Currently, I think
it best to initially learn OOP with as little fanfare as possible: by
treating OBJECTs as just another programming construct, and using more
typical examples, or at least ones that are easy to relate to.

If you have implemented Turbo Pascal Units (and know records), you will find
it easy to implement TP OBJECTS (especially if you avoid virtual methods and
dynamic objects at first).  You may start with something simple such as an
abstract data type that you have already implemented as a UNIT.  It's then a
matter of placing data fields and method headings together in an object. Try
an array implementation of an Integer stack even though there are may be no
descendants.

Borland's DragIt operation (explained in their OOP guide) was enough
motivation to look further into virtual methods but I found abstract objects
such as BankAccount and LibraryItem were more appropriate at this point.  These
are simple objects that have easily identified descendants, common
operations and data fields.  Thinking in is-a relationships, a Savings
account is-a BankAccount with an ApplyInterest operation.

I found virtual methods easier to comprehend after I had time to let some
simple object implementations and basic OOP concepts to sink in.
Again, simple objects were better than more complex ones at first.  For
example, a Book is-a LibraryItem that may have a Fine operation called in an
abstract operation called LibraryItem.Return.  Other descendants of
LibraryItem may have different Fine and CheckOut operations called when the
abstract operation LibraryItem.Checkout is eventually reached.  For
instance, A VHSTape is-a LibraryItem with a two dollar borrowing charge.
This virtual method should display a message like 'Please pay $2.00'
whereas Book.Checkout would not.

The next thing to tackle is Dynamic OBJECTS.  (Thomas: I had trouble wading
through UNIT Objects also).  Things became less muddy when I implemented a
Stack and a Queue by extending OBJECT Node and OBJECT List contained in the
Objects unit distributed with Turbo 5.5.  Implementing these common abstract
data types required overcoming these hurdles:

    Typecast operations are necessary to override Turbo's one-way object
    type compatibility.

    Use of the Self parameter to find the previous node in FUNCTION
    Node.Prev was a bit awkward to understand although it does save the
    extra pointer field of a doubly linked circular list.

    The documentation (OOPDEMOS.DOC) claims that procedure Append will
    append a node as the first node on the list.  Actually, the new
    node becomes the last (at least I think so).

    PROCEDURE New and PROCEDURE Dispose have been extended
    to also act like functions.  In order to extend OBJECT List,
    careful attention must be paid to this dual use of New and
    Dispose when inserting or appending nodes.

All in all, extending Objects List and Node was one way to experience the
extension (modification) of a unit containing objects without changing that
source code.

Rick Mercer
Penn State Berks Campus
oxc@psuvm

dmo@cs.vu.nl (=Osinga Douwe M) (10/09/90)

Hi,

How do I change the default (8x8) font used by GRAPH? And why does the
hercules card driver not include characters above 128? Anybody with an
answer to any of these questions please email or send to the news.

       Douwe M Osinga. (dmo@cs.vu.nl)

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (10/10/90)

In article <7877@star.cs.vu.nl> dmo@cs.vu.nl (=Osinga Douwe M) writes:
>Hi,
>
>How do I change the default (8x8) font used by GRAPH? And why does the
>hercules card driver not include characters above 128? Anybody with an
>answer to any of these questions please email or send to the news.
>
>       Douwe M Osinga. (dmo@cs.vu.nl)

  Two possibilities come to mind:

  1.  You haven't read your documentation thoroughly enough.  You seem
  to know that the default font is indeed 8x8 and is used by Graph, but
  haven't discovered the 'settextstyle' function.

  2.  You don't have proper documentation, which invites unlimited 
  speculation...

  Either way, look up 'settextstyle'.

  As for the Herc question, sorry, I've never owned one.