Real world method examples for public, protected and private

People,

I have been following the “Stoooopid OOP question” stuff and I went
looking for some real-world examples of when to use the different sorts
of methods but all I can find are silly “foo / bar” type examples - can
someone point me to some simple examples that show me why there are
cases when methods should not be public?

Thanks,

Phil.


Philip R.

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: [email protected]

On Sep 6, 2014, at 9:40, Philip R. [email protected] wrote:

People,

I have been following the “Stoooopid OOP question” stuff and I went looking for
some real-world examples of when to use the different sorts of methods but all I
can find are silly “foo / bar” type examples - can someone point me to some simple
examples that show me why there are cases when methods should not be public?

Not sure how simple this is, but its fresh in my mind:

Most of the public methods are part of the API that normal users of this
gem will see: initializing, incrementing, decrementing, and inspecting
the counter.

The two private methods arent for public use. They allow the counter to
be deserialized by methods in the parent class, and for the parent class
to serialize counter operations.

Bryce,

On 2014-09-06 23:52, Bryce K. wrote:

Not sure how simple this is, but it???s fresh in my mind:
riak-ruby-client/lib/riak/crdt/counter.rb at master · basho/riak-ruby-client · GitHub

Most of the public methods are part of the API that normal users of
this gem will see: initializing, incrementing, decrementing, and
inspecting the counter.

The two private methods aren???t for public use. They allow the
counter to be deserialized by methods in the parent class, and for the
parent class to serialize counter operations.

OK, that makes sense - thanks for that.

Regards,

Phil.

Philip R.

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: [email protected]

Bill,

On 2014-09-07 00:44, Bill F. wrote:

Very hard to beat:
Practical Object-Oriented Design in Ruby: An Agile Primer
(Addison-Wesley Professional Ruby Series) by Sandi Metz

Lucky there was a Kindle version so I bit the bullet and bought a copy .
.

Thanks!

Phil.

sorts of methods but all I can find are silly “foo / bar” type
GPO Box 3411
Sydney NSW 2001
Australia
E-mail: [email protected]


Philip R.

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: [email protected]