Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^4: OOP's setter/getter method - is there a way to avoid them?

by mr_mischief (Monsignor)
on Nov 05, 2015 at 14:45 UTC ( #1146991=note: print w/replies, xml ) Need Help??

in reply to Re^3: OOP's setter/getter method - is there a way to avoid them?
in thread OOP's setter/getter method - is there a way to avoid them?

Using the bank account example, though, what if I just want to check my balance? What if I just want to check the date of account creation, or verify my account number? No actual mutation is necessary, but it would be handy to access those values. There wouldn't be a need to mutate those directly, but accessing them without making a deposit or withdrawal should be possible. I suppose you could have a method called query_balance that returns the balance and also updates a log of the query.

Replies are listed 'Best First'.
Re^5: OOP's setter/getter method - is there a way to avoid them?
by BrowserUk (Patriarch) on Nov 05, 2015 at 15:27 UTC

    Indeed. There are always going to be some attributes that need to be queried. Further, there are some attributes that need to be set directly and in isolation. Eg. If you move the address need to be updated. If you change your pin. Etc.

    Of course, the former is likely a part of a Customer Class; and validation of the address is likely performed by a different processing application long before that information is wrapped up in a transaction and applied to the actual Customer record.

    And the latter is likely part of a CreditCard class; and again validation and verification checks performed outside of the process that updated the master records.

    But the point holds; accessor and mutator methods should be added deliberately as a designed requirement for those attributes that require them for the functional operation of the class; not generated automatically regardless of the need.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-12-09 22:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found