FW: [boulder.pm] oo perl

Justin Crawford justin.crawford at cusys.edu
Thu Mar 16 11:25:01 CST 2000


I'm just learning OO in perl myself (haven't got the book yet...), but one of the best things I did was to take a big old script of mine that was sloppy and ugly and functional, and envision it as a set of objects, and then recode it (surprisingly with a lot of the same code, just in different places).  What I end up with is a much more useful set of thingies that are logically separated.  And maintainable.  I'm just deleting the remnants of the old procedural bear now.

Or, if you like, you can try this one ( I think it's a pretty standard OO lesson, I got it in Java class ):  Code yourself a circle class, and make circle objects with different radii.  What do those objects need to be able to do?  Well, they could have a method to 'set' the radius, a method to 'get' the radius, a method to calculate the circumference, one to calculate the area.  Then code yourself a driver to interface with the user, ask the user how many circles and what radius each should start with, and present the user with various things to do to a particular circle object.  The driver instantiates the circles and sends them messages.

Our next project is to code a business card application.  So there is a business card class, a field class, and a driver.  Objects of the business card class contain one or more objects of the field class, and the driver prompts users to choose an operation.  Possible operations:
-make card (set size, texture, color, number of fields [which then opens up the edit field dialogue, and the field object attributes are: text, fontsize, x-coordinate, y-coordinate])
-view card (I'm a unix guy, so I just get the cards specs and dump them in text to the screen, i.e. "size = 2 x 3")
-edit card

You have the added complexity in #2 of having multiple card objects, each of which is associated with multiple field objects.  The driver is still the hardest part of this, but dealing with the objects in the driver makes you really think about datastructures and methods and junk. 

Anyway, hope it's useful, have a good day.  Don't forget to throw a snowball.

justin

PS: I'm sorry if this langage is javacentric, I'm learning perl by myself and Java in a class so I get all that stuff pushed in.  Flame away y'all!

Justin Crawford
Oracle DBA Group
University Management Systems
(303) 492-9083
justin.crawford at cusys.edu

-----Original Message-----
From:	SMSRussell at aol.com [SMTP:SMSRussell at aol.com]
Sent:	Thursday, March 16, 2000 9:44 AM
To:	boulder-pm-list at happyfunball.pm.org
Subject:	Re: [boulder.pm] oo perl

In a message dated 3/7/00 9:37:24 PM Mountain Standard Time, 
jmaslak at mindspring.com writes:
<< I'd also be glad to
 answer "real world" OO questions, although I didn't read the book
 mentioned previously, and, thus may come at it from a different angle! >>

I'm not at the point yet of having "real-world" questions. I'm still 
struggling through the early chapters of Conway's book. Do you (or anyone 
else on the list) have any suggestions for not-too-difficult exercises to try 
and get started in oo? I like Conway's book, but he doesn't include any 
additional exercises for the reader, and I'm one of those people that works 
better being "forced" to solve a problem, rather than just looking over 
someone else's code!
Thanks,
Susan




More information about the Boulder-pm mailing list