Abstraction VS Information Hiding VS Encapsulation

Go to the source! Grady Booch says (in Object Oriented Analysis and Design, page 49, second edition): Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object… encapsulation focuses upon the implementation that gives rise to this behavior… encapsulation is most often achieved through information hiding, which is the process … Read more

How do I return a reference to something inside a RefCell without breaking encapsulation?

You can create a new struct similar to the Ref<‘a,T> guard returned by RefCell::borrow(), in order to wrap this Ref and avoid having it going out of scope, like this: use std::cell::Ref; struct FooGuard<‘a> { guard: Ref<‘a, MutableInterior>, } then, you can implement the Deref trait for it, so that it can be used as … Read more

When should you use ‘friend’ in C++?

Firstly (IMO) don’t listen to people who say friend is not useful. It IS useful. In many situations you will have objects with data or functionality that are not intended to be publicly available. This is particularly true of large codebases with many authors who may only be superficially familiar with different areas. There ARE … Read more

Why are Python’s ‘private’ methods not actually private?

The name scrambling is used to ensure that subclasses don’t accidentally override the private methods and attributes of their superclasses. It’s not designed to prevent deliberate access from outside. For example: >>> class Foo(object): … def __init__(self): … self.__baz = 42 … def foo(self): … print self.__baz … >>> class Bar(Foo): … def __init__(self): … … Read more