in reply to Re: How do I go from procedural to object oriented programming?
in thread How do I go from procedural to object oriented programming?
You have a class called Movies.
You have an object called movie. (It's currently stored in your Perl scalar called $movie).
But this simple example belies the power of OO.
You can now create multiple instances of that object.
Firefly is a movie (as defined in your original hash, anyway). But so is Iron Man. And so on.
Each of these is an instance of the movieobject, from the Moviesclass.
You can create any number of movieobjects as you need in your code, for whatever purpose.
my $oldFavorite = Movies->new(title=>"FireFly"); my $newFavorite = Movies->new(title=>"Iron Man"); $oldFavorite->setMedia("tv"); $newFavorite->setMedia("film"); $oldFavorite->demote(); $newFavorite->promote();
This wasn't meant teach you to code OO; it was meant to demonstrate how OO changes the way you look at programming.
If it helps, great.
If not -- well, I tried.
Good luck!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How do I go from procedural to object oriented programming?
by Anonymous Monk on May 06, 2015 at 22:00 UTC | |
by Anonymous Monk on May 07, 2015 at 02:30 UTC |