Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 19 May 2013, 21:06
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
OOP and Delphi/Lazarus
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
minesadorada


Joined: 11 Sep 2011
Posts: 67

PostPosted: Wed 04 Apr 2012, 06:18    Post subject:  OOP and Delphi/Lazarus
Subject description: Case study
 

Thanks to Puppy and Lazarus, I have got back into Pascal programming (only as a hobby nowadays - I'm retired) I'd almost forgotten how simple, elegant and powerful it was.

The application is an USGA/EGA Golf Handicap calculator.

It uses data from a golf club (different for each course and tee position, and dynamic in size too) to calculate EGA handicaps, playing handicaps and adjustments to handicaps.

I wrote the logic as a self-contained object (with a separate GUI interface which gets/sets the properties and calls the methods), and it had an abstract method 'GetCourseData', since the data could come via direct input, a database, an XML file - anywhere.

So using the original object as ancestor I extended it into a child object that implemented GetCourseData to read golfml (open source XML standard) files.

The advantage of this OOP method is that I could just as easily extend the ancestor to implement GetCourseData as a method to read a database, or any other data format, and the ancestor properties and methods would be the same, as would any GUI based on it.

When designing a course data writer, again the OOP method has advantages.
1 ) Write a data-entry user-friendly GUI
2 ) Write (or re-use) an ancestor object to receive and store all the data from the GUI (via property access) and have an abstract method 'WriteCourseData'
3 ) Subclass it and implement the WriteCourseData method to write the stored course data in particular formats.

This means the same ancestor object can be used as a base to load and save golf course data in as many formats as you have subclasses, with a standard GUI for input, and various GUIs to display or use the data.

Lazarus object pascal makes this process of isolating input, processing and output particularly easy, and the GUIs will compile for a good variety of platforms without having to alter code. Of course it makes maintainance and bugfixing a lot simpler, too.

I'm currently implementing the writer subclass for the golfml format.

Does anyone else here use OOP as their first-choice solution?
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2196
Location: Gatineau (Qc), Canada

PostPosted: Sun 08 Apr 2012, 18:33    Post subject:  

Euh... what does the acronym "OOP" stand for, please?

Thanks in advance.

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Sun 08 Apr 2012, 18:46    Post subject:  

musher0 wrote:
Euh... what does the acronym "OOP" stand for, please?

Thanks in advance.


Object Oriented Programming.

In German: Objektorientierte Programmierung.

I am not sure, but i think it mostly means GUI-Building, but can also mean Objects like Classes etc.

Please, minesadorada, do correct me, if i am totally or partially wrong.

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
minesadorada


Joined: 11 Sep 2011
Posts: 67

PostPosted: Mon 09 Apr 2012, 05:38    Post subject: OOP  

The basic idea is to isolate data within a block of code called a class or object. The object then has a public API which manipulates the hidden data.

Access to the private data is only via public methods and properties (the API). By controlling data access in this way, the code to access and manipulate it can be thoroughly debugged with access to the data invisibly type, range and exception checked. (development debugging is usually using a simple and temporary GUI)

There's a decent wikipedia article on it here: http://en.wikipedia.org/wiki/Object-oriented_programming

The trick with OOP is to plan ahead, and consider data structures and objects before starting a programming project. In that way, you can save yourself not only lots of redundant code, but also have a simple and clear development/debugging/optimising path to follow. OOP also makes you think about scope issues from the start.

You don't get instant results when coding in this way, as the object hierarchy has to be built from the base upwards, and the initial coding of properties and methods can be quite boring, but believe me - the results are worth it, and the objects are often re-usable for other projects.

The real power of OOP comes with inheritance and polymorphism via abstraction which you'd be better off Googling for a full explanation. My golf application class/subclasses used all three.

Some people make out that OOP is difficult, but that's a complete myth, and as I said in the first post - Lazarus/FPC can help you do OOP with ease.
Back to top
View user's profile Send private message 
minesadorada


Joined: 11 Sep 2011
Posts: 67

PostPosted: Sun 22 Apr 2012, 09:34    Post subject:  

Project golfml stage 1 finished now. I ended up rolling up the golfml Writer and Reader class into one object.

Here's a summary of the class: http://www.charcodelvalle.com/golfmlweb/golfmlclass.html

Applications and Lazarus source code at http://www.charcodelvalle.com/golfmlweb/

The apps run on Linux 32 and 64 bit (as well as windows). All opensource, so feel free to download and play.

Stage 2 is making up xsl stylesheets, and it's been some years since I did xml/xsl transformations.
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 278

PostPosted: Sun 22 Apr 2012, 14:45    Post subject:  

minesadorada wrote:
Project golfml stage 1 finished now. I ended up rolling up the golfml Writer and Reader class into one object.

Here's a summary of the class: http://www.charcodelvalle.com/golfmlweb/golfmlclass.html

Applications and Lazarus source code at http://www.charcodelvalle.com/golfmlweb/

The apps run on Linux 32 and 64 bit (as well as windows). All opensource, so feel free to download and play.

Stage 2 is making up xsl stylesheets, and it's been some years since I did xml/xsl transformations.


I tend to use FreePascal.

On large projects, the parent type I usually start the tree with is one that knows how to read and write its self from and to the configuration file. Really the base type only writes its type value out and nothing more. The children know who to write the properties that matter. This way it is easy to write a thing to save the session and load a saved session and things like that.

If you do it right, the saved sessions work across versions. This way, when you find a bug, you can save the session and reload it for testing in the corrected version.

The only hard part is writing the bit that goes through the types looking for the matching one. This is done with a linked list of the methods that check for a match and then conditionally call the constructor on a match.
Back to top
View user's profile Send private message 
minesadorada


Joined: 11 Sep 2011
Posts: 67

PostPosted: Sun 29 Apr 2012, 02:22    Post subject:  

Moose On The Loose wrote:
]

I tend to use FreePascal.

On large projects, the parent type I usually start the tree with is one that knows how to read and write its self from and to the configuration file. Really the base type only writes its type value out and nothing more. The children know who to write the properties that matter. This way it is easy to write a thing to save the session and load a saved session and things like that.

If you do it right, the saved sessions work across versions. This way, when you find a bug, you can save the session and reload it for testing in the corrected version.

The only hard part is writing the bit that goes through the types looking for the matching one. This is done with a linked list of the methods that check for a match and then conditionally call the constructor on a match.


@Moose On The Loose: Have you example code to share?

I just installed Tortoise SVN for windows. Oh my! What an improvement from years ago when I last used it for an open-source project. Now much easier than Visual Sourcesafe 5 Sad which I was forced to use when I was working commercially.

I can add and commit via right-click in explorer and it even hooks onto the move-copy drags in Windows.

Hopefully someone will compile a Puppy GUI PET for svn (I couldn't find one on the forum)

I'm working with code.google.com which is first-rate and free.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0657s ][ Queries: 12 (0.0134s) ][ GZIP on ]