Lots of people swear by the book "Design Patterns". I am finding Object Oriented Perl
to be a very useful book.
The best advice I can give you is to do a lot of thinking, a bit of research on how objects are handled in other languages, and a lot of diagramming how real world things are put together.
For example, suppose you are designing a race track. You know you will need a track, cars, and spectators. What are the similarities of all of those things that you can generalize into a parent object? What are the differences (that matter to your application) that you want to list specifically in each object? Are there any special types of any object that would best be served by subclassing it?
- Track... no big thing here. Seems like a one-shot object.
- Cars... at the very least, things like acceleration, tires, and engines will be different. Maybe they each need to be subclassed, maybe they can just be member attributes.
- Spectators... size of hair, number of velvet Elvis paintings owned, days since last tornado, these can all be member attributes. Perhaps you can define subclasses for gender.
Okay, it's not the greatest example, but if you do that for real-world things a few times, you'll get better at it. It helps to know exactly what kind of data you need now. Then worry about making it more flexible later.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||