Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: High level OOP query

by packetstormer (Monk)
on Oct 24, 2013 at 13:18 UTC ( #1059452=note: print w/replies, xml ) Need Help??

in reply to Re: High level OOP query
in thread High level OOP query

Thanks for the detailed response, Ken. I really appreciate it.

The code I posed was just for ease of reading and I would expect to split the class out to it's own package file when in use

I am working my way though the book "Intermediate Perl" at the moment but I would love to find some real world examples that are simple enough for me to read. I have looked at many packages (from CPAN and other devs) but they are still a little complex for the standard I am at and I find trying to work them out is very time consuming due to their large size

I will battle on though and thanks again for the reply.

Replies are listed 'Best First'.
Re^3: High level OOP query (internal data)
by Anonymous Monk on Oct 25, 2013 at 00:34 UTC

    However, is it the "norm / acceptable", as above, to check the argument and based on a value then modify it.

    It is acceptable to modify any attributes based on arguments

    They say the user of a class shouldn't know/care about the internal state of attributes -- attributes are an implementation detail for the writer of a class

    so as the writer of a class do what makes sense, but as the user of a class pretend you don't know how it works inside (hard I know)

    smart people say: design a class the way you want to use it, start by writing code that uses it first

    perlootut, Modern Perl, Moo

    OR, is it better/normal to create a "blank" instance and then pass that into another method to change/modify?

    That depends, does the change/modification happen only once, during object creation? Or can it happen at any time in the life of the object?

    If you allow the user of your class to modify user/pass after object instantiation, and some other attribute depends on user/pass , then its best to encapsulate this relationship in a seperate method

    Instead of allowing ->change_username and ->change_password, call it ->change_userpass, and document that it affects the value of append_text

    But most likely you'll simply want to stick with doing this in the constructor -- and not allow changing of user/pass after instantiation

    OR, the third option: I am getting way to bogged down on what is the "norm" and I should worry more about my apparent lack of understanding of how OOP works!

    This! I recognize you as a one-of-us who doesn't really understand how OOP works :)

    This question is more of a low-level detail and you're not going to ferret out any benefits/tradeoffs/caveats... to find the best approach in this project -- its just not big enough and this detail is very low level

    No matter what you do, you're going to get it wrong, so you might as well get on with it, write your code (deliver product), make your mistakes, and learn from them :)

    The part you're probably missing
    Class-responsibility-collaboration card
    GRASP (object-oriented design)
    OOP in the Real World - Creating an Equation Editor - CodeProject
    How I explained OOD to my wife - CodeProject
    A Simple Example of Object-Oriented Design: An Address Book and An Example of Object-Oriented Design: An ATM Simulation ; tarballs at
    Story-driven modeling

Re^3: High level OOP query
by sundialsvc4 (Abbot) on Oct 25, 2013 at 00:08 UTC

    Just remember that every one of us fought that same battle, from time to time felt just as lost and just as stupid, and that from time to time we still do.   It comes with the territory.   Meditate on all of the responses (present one excepted?) that you have received so far.   “Welcome to Perl,” and keep us up-to-date of your progress down The Path.   Bounce questions off of us (boink!!) anytime.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1059452]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-02-20 04:30 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (267 votes). Check out past polls.