ArianeSoft - Programming and development for Windows and Windows Mobile :: Forums :: PPL - Pocket Programming Language :: Code sharing
 
<< Previous thread | Next thread >>
OOP example with OOP tutorial
Moderators: kornalius, bmanske, PointOfLight
Author Post
Donone
Sat Dec 01 2007, 02:30pm
Registered Member #231
Joined: Fri Jan 12 2007, 10:17am
Posts: 626
This is a simple example of OOP using two classes, one calling the other, to produce a status bar with up to four built-in panels.

It is left without events and other accoutrements in order to be straightforward for use with the short introductory tutorial on OOP and Class for anybody who feels a need.

For a more in depth example with events see the earlier posted example of PathSprite.

I hope this proves useful for somebody who hasn't and wants to get off the ground, Classing.
The code is documented.
It has only been tested on the desktop because it is to demonstrate principles.
The other docs are in PDF and DOC format.
1196537414_231_FT0_oop_example.zip
1196537415_231_FT0_oop-docs.zip

This is intended to be a progressive series that builds up the Status Bar (but it could be anything) and indicate where earlier decisions will need changing in order to implement later adaptations.
The next version will modify the surface used and permit text to be added to any panel, this will require modifying the panel structure.

In doing so it will illustrate the golden rule that a Class must always be backwards compatible so as not to break any existing user programs. We can change the internals but the interface must remain the same except for additions.

[ Edited Sun Dec 02 2007, 03:31am ]

You only stop learning when you die.
Sometimes I think I am dead
http://www.don-simmonds.co.uk
Back to top
Donone
Sun Dec 02 2007, 04:13am
Registered Member #231
Joined: Fri Jan 12 2007, 10:17am
Posts: 626
The next stage in the OOP Status Bar is attached.
The changes are clearly documented and they are in the Class file Lines 38 to 50 and Lines 86 to 93.

The improvement is that the Panels have had to be modified because they weren't suitable for adding then changing text without a lot of difficulty and the panels were not truly independent. The old system would have required redrawing the whole in order to change the text on any one panel.

A separate surface is now used for each Panel and of course it is stored within each object so that we may use it again.
The same test program is used because of course it is not affected by the changes within the Classes used. Only the mechanism has changed, not the outcome.

The next step will be to add text to individual Panels, and show that we can add some extra properties that will allow the text to be changed.

The original test program will still work. We are still using the same two interrelated Classes.


1196586781_231_FT8230_oop_example-1.zip
[Addendum] In the test program change Line 2 #include to read "ClassStatus-1.ppl"

[ Edited Sun Dec 02 2007, 04:34am ]

You only stop learning when you die.
Sometimes I think I am dead
http://www.don-simmonds.co.uk
Back to top
Donone
Sun Dec 02 2007, 09:43am
Registered Member #231
Joined: Fri Jan 12 2007, 10:17am
Posts: 626
The third part of this example has changed on the following lines in the Class file...
Line 7 Privatising the panel surface.
Lines 37 to 44 Using a permanent surface for panel
Lines 50 to 61 New Property - Current Panel Text
Lines87 to 89 Alternative main Status Bar.
Lines 149 to 157 New Property StatusBar Text for any panel.

Note that all these changes have not affected the original program, which still runs perfectly.
However a new section has been added to the end Lines64 to 65 which pass text to 2 of the panels in different colours.
This text can now be changed at will without touching the code in the Classes, this is the whole point of the exercise.

The next most obvious steps are to make it possible to retrieve the text and colour from the panels at any time, by creating two more properties.
I'm sure you will manage it.

I hope this has been useful to at least one person.
Study the 3 parts in sequence and it should all become clear. Then add a few bits yourself.
THEN create your own from scratch using this as a reference.
Over time I have had help from this forum, PointOfLight and kornalius mostly, but a few others chipped in. Finally putting all this together and practicing is what instills it in the mind.

Any questions or criticisms, modifications, corrections, simplifications etc. please post them.
Have fun
1196606344_231_FT8230_oop_example-2.zip

[ Edited Sun Dec 02 2007, 10:40am ]

You only stop learning when you die.
Sometimes I think I am dead
http://www.don-simmonds.co.uk
Back to top
kornalius
Sun Dec 02 2007, 12:50pm


Registered Member #1
Joined: Wed Apr 19 2006, 08:25pm
Posts: 2783
Thank you very much for this very informative and very easy to understand tutorial. Keep them coming.

Regards,
Alain Deschenes
President and programmer
ArianeSoft Inc. (http://www.arianesoft.ca)
Back to top
Donone
Tue Dec 11 2007, 06:07am
Registered Member #231
Joined: Fri Jan 12 2007, 10:17am
Posts: 626
For some reason DVT_NONE does not work on Line 57 of ClassStatus-2.ppl it should be changed to 0 (zero).
Once that change is made all works fine.

Can anyone say why that does not work?

You only stop learning when you die.
Sometimes I think I am dead
http://www.don-simmonds.co.uk
Back to top
PointOfLight
Tue Dec 11 2007, 08:43am

Registered Member #49
Joined: Sun Sep 17 2006, 03:02pm
Posts: 1129
I must be missing something, because if I replace DVT_NONE with 0, the output looks the same to me.

Eric Pankoke
Founder
Point Of Light Software
http://www.polsoftware.com/
Back to top
Donone
Tue Dec 11 2007, 09:15am
Registered Member #231
Joined: Fri Jan 12 2007, 10:17am
Posts: 626
Ah...
so it should, but DVT_NONE doesn't work on my system but don't know why, it did when I wrote it.

As a passing comment, I noted your comment regarding no Sprite Procedure. This class doen't need it it is static.
The main example of oop was the Pathsprite (posted earlier) one which uses events and a sprite procedure within the class.

[ Edited Tue Dec 11 2007, 09:16am ]

You only stop learning when you die.
Sometimes I think I am dead
http://www.don-simmonds.co.uk
Back to top
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System