Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object oriented Design 6

Status
Not open for further replies.

SPrelewicz

Programmer
Jul 16, 2001
124
US
i apologize if this is sort of semi-perl related, but I figured the best palce to come.

I'm making the step into OOP for my larger web based apps and would like some advice about how others layout their OO Perl apps. I will be using CGI::Application and all its plugins, etc.

My project now is a Sports stats/data site, back-end for entering player data game by game, front on world wide accessible displaying data. [Nothing unusual] i will be using mySQL.

So, I am confused about what to classify and things. I'll need a data layer, but where do i put that and how to let my other classes know about it. Say I have a Player class with position, name, etc...then a Basketball Player class with stats, ability to score point, get rebounds, etc. How then does the data loading/saving into the mySQL DB fit in. Are those methods in the Player class, should they be used to instantiate the object, should I have a separate DATA class I 'use' in all my other classes.

Also, in OO design, is it common to create an array of many objects at once, as in a roster of basketball player objects, and if so how does this affect performance?

Thank you in advance for your time.

Scott

About me at Flying Roman.com lyric meaning and discussion
Prelewic, Renassance Man ;)
 
so a class is a bunch of functions, you call them to define an object, then what do you do with this object ?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Think back to my example of the television remote control.
Once you have the class of "remote" defined you can create "remote" objects.
The you can use them exactly as you would any other object in the real world.
You press buttons (or in the case of code you call methods) and things happen!
You could have a shape object for example and call the "draw" method on it.
If you have an array of shapes, each one would know what kind of shape it was and you could just call "draw" on each one in turn. They would each draw themselves and you would not have to care what kind of shapes they were. They manage that for themselves. They could manage their own pen thickness and colour too.


Trojan.
 
but couldn't you do the same by having a function called draw which was passed parameters or read in parameters from a database to achieve the same thing?

I take it draw would need to be written to understand a class rather than work from raw data and then you pass the class to draw.

I don't see the difference ....

function draw can be written either to read all the data from the class to draw the shape or you pass it the details along with pen size etc.. or you store this data in memory in an aray or in a db, isn't it all the same thing at the end of the day?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF,
just curious, which language(s) do you usually program in?
 
PERL, VBA for MS Access are the two I use mainly, but I have dabbled with ColdFusion, obviously i have to code HTML and use JavaScript all the time also, plus you can't avoid using the odd bit of CSS either.

I used to program Gener/ol, Rexx, Paradox and other 4GL type languages such as Informix, many were in a mainframe environment, before PC's took over the world!

Why?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
ok, just found it odd that you didnt know what OO programming was (not the details but the concept)
 
The big difference is in how the draw method works.
Some shape classes might not have one at all, they might inherit it.
If you add a shape that needs completely different drawing functionality, you rewrite the draw method for that one shape only. It will not affect any code that you have already tested and is working.
In your scenario you would hack about the draw function and have to re-test everything.
Also, how can you keep an array of shapes with your scenario when each shape has all these individual characteristics like colour, line thicknes etc?
Another issue.
Say you changed from 2d to 3d drawing. With objects, you just change the draw methods and all the remaining code continues without noticing the change.
In the linear code world you are much more likely to have to make serious changes to the main code which means you may as well bin everything and start again.
Objects can make a massive difference if you know how to use them.
Also, testing them is so much simpler. You can write a separate, stand alone t.pl to test just that object. If you have a draw function in linear code, the chances are you're tied to lots of globals and therefore cannot extract it for testing.



Trojan.
 
I probably use it all the time especially when programming in VBA, hooking into the windows API or OUTLOOK, WORD, EXCEL etc..

I use it , I don't understand it, I guess that can be the beauty of programming, any old idiot can do it, it takes a genius to understand it properly.

I ask these questions because i'd like to understand, and thanks to the kind and generous people like Trojan, Fishiface, Ishnid, KevinADC, etc, i understand more than ever and have improved my coding over the last few years dramatically.

I have the utmost respect for these people and many here on Tek-Tips, if nothing else for putting up with idiots like me asking stupid questions, but hey they must like it else they wouldnt reply :p

I wish i understood OO I'm sure i'd benefit from it , but i'm still stumped as to the real use or how i would build my own or use current ones available.

I'm stuck to writing every thing myself line by line to achieve my goals, not ideal but it gives me the results i need, in the time i have.

maybe one day i'll understand and will make better apps, so keep ya fingers crossed for me



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I hear ya Trojan, maybe i need to send myself to college, i take it once you grasp the concept of OO , then any language is the same.

I think I need to set myself a task, then use OO to create it.

Not sure what, like i say I think if i sent myself back to school it would make it clearer how it all fits together, i could then use that to re-write my apps.

Hey that's how i ended up with my SQL module and alike, thanks to you lot, before my code sucked big style, no use strict, variables a mess, now i have my apps using modules I wrote myslef and all my variables are defined.

next step Objects, Classes & Methods..... who knows one day I might be able to hold my head up high and call myself a programmer.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
You are absolutely right, you do use objects and don't realise it. One of the big advantages of objects is exactly that. The code can be made so simple to use that you don't realise the complexity of what is happening.

I wish you luck with your goals.


Trojan.
 
1DMF

I know this is the perl forum and all, but if you want to get started with OO concepts, then perl definitely isn't the cleanest implementation on the block. You might be better off with a different language to learn the basics of OO, then mapping the concepts back onto perl. Java, C#, or dare I say Ruby (never tried it, supposed to be like OO perl) might be better for learning the concepts.

Making the step from procedural programming can be tricky, but don't worry - your procedural coding skills will stand you in good stead inside your methods.
 
Not sure I agree there.
Perl's OO design is unusual but generally very simplistic and yet fully functional. I believe it's a good easy way to learn about OO programming without getting bogged down in the details of copy constructors, destructors, multiple inheritance, virtual base classes, property visibility and all hairy kinda stuff that often just gets in the way.
I realise that all these issues can apply to perl but they tend to be much more rare and much simpler to deal with.


Trojan.
 
I dont have time to respond individually, but this thread and discourse and debate has been very enlightening.

Indeed, this isnt a concept to take light-heartedly. I think where alot of frustration for people like myself and others new to OO is that perhaps it is so simple you tend to over-think and second guess what you are doing.

It's good to see others employ similar concepts that I thought of but wasnt sure if I was correct.

Thanks,

Scott

About me at Flying Roman.com lyric meaning and discussion
Prelewic, Renassance Man ;)
 
Ruby - WTF is that , man I can't keep up, Just as I think i'm grasping something, the goal posts move. The only goal I end up scoring is an own one - lol.

but i think i've grasp the concept, i've been thinking hard on what trojan said and I've come up with this synopsis, i'd appreciate a nod if i've got it right.

My theory is this....

My 'Object' is a car..... ( automobile or vehicle for our freinds across the pond :p )
the 'Classes' would be the wheels, the doors, the mirrors, etc..
the 'Methods' are the functions that make the wheels go round, or the windows move up and down...

is that the right way of thinking ?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The car is both a class and an object.
You can't have a car unless someone knows what a car is.
The class "car" is the design of the car. The blueprint if you like. The instance is YOUR car.
The same applies to the wheels, doors, mirrors etc.
You are right about the methods.
The properties that the "car" class maintains might be "current gear", "current speed", "steering direction".


Trojan.
 
so what is purely an object

the track it's on, the trees around it, the buildings, the sky , the sun ?
all of those are classes the thing they are all in is the object ?

man just when you think you've got something - lol

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I'll take a shot.

Think of a dog. I say the word dog, and you can picture a dog in your head. It has a tail, 4 legs, hair, gives birth to live young, carnivore, etc... ALL dogs have these things. This is the class of dogs.

Now, YOUR DOG, Sparky, is an OBJECT of class DOG. The difference being, when you create an object from class dog, you now have a tangible, specific Dog [Sparky] which exists, and is an object of the class dog you think of when I say the word dog.

About me at Flying Roman.com lyric meaning and discussion
Prelewic, Renassance Man ;)
 
lol
The CLASS is the design. It's the blueprint or the description. It's the kit of instructions to make something.
The OBJECT is the thing that gets made with those instructions.

You can think of the CAD designs of a car as the CLASS and the actual car you drive as the OBJECT.

Does that make it any clearer?


Trojan.
 
but thats what i said to start witrh the car is the object - but you said the car was also a class - agghhh my head hurts

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Okay.

So trojan, my Dog example grasps the concept okay, no? Its similar to what you're saying, in my example the design would just be the mental picture when thinking of class DOG.

Anyway, the concepts I think Im well enough aware of, its the process of turning a specification into a OO design. Like in my original problem, I want to track sports stas, so, I could make a Game class with Player Components that have Stats Components, etc. Player is a sub-class of Person, as Coach is subclass of Person. Am I on the right track?

Then a data layer and a GUI layer is introduced, and I start getting all befuddled. Your [and others] processes you discussed above are helpful.

Scott

About me at Flying Roman.com lyric meaning and discussion
Prelewic, Renassance Man ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top