Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: How do I go from procedural to object oriented programming?

by marinersk (Priest)
on Apr 20, 2015 at 23:22 UTC ( [id://1124088]=note: print w/replies, xml ) Need Help??


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
    One of the benefits of OO is being able to organize your thoughts and design your solution. OO tends to persuade the coder to not just bash out a bunch of code, but instead plan and refactor. What you did was post 7 nodes of stream-of-thought off the top of your head consciousness without bothering to write a rough draft and refactor your repeated thoughts. Very non-OO.

      One of the benefits of OO is being able to organize your thoughts and design your solution. OO tends to persuade the coder to not just bash out a bunch of code, but instead plan and refactor. What you did was post 7 nodes of stream-of-thought off the top of your head consciousness without bothering to write a rough draft and refactor your repeated thoughts. Very non-OO.

      And very much appreciated.

      Compared to just blobs of code almost everybody always posts , watching somebody go through their thinking process is very much appreciated -- its practically priceless.

      How the fuck can you complain about that?

      You can't skip steps and arrive at a solution and understand why you got there and why its good

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found