Using a strategy pattern and a command pattern

I’m including an encapsulation hierarchy table of several of the GoF design patterns to help explain the differences between these two patterns. Hopefully it better illustrates what each encapsulates so my explanation makes more sense. First off, the hierarchy lists the scope for which a given pattern is applicable, or the appropriate pattern to use … Read more

Must Dependency Injection come at the expense of Encapsulation?

There is another way of looking at this issue that you might find interesting. When we use IoC/dependency injection, we’re not using OOP concepts. Admittedly we’re using an OO language as the ‘host’, but the ideas behind IoC come from component-oriented software engineering, not OO. Component software is all about managing dependencies – an example … Read more

Difference between Encapsulation and Abstraction

Encapsulation hides variables or some implementation that may be changed so often in a class to prevent outsiders access it directly. They must access it via getter and setter methods. Abstraction is used to hide something too, but in a higher degree (class, interface). Clients who use an abstract class (or interface) do not care … Read more

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

Understanding the difference between __getattr__ and __getattribute__

Some basics first. With objects, you need to deal with their attributes. Ordinarily, we do instance.attribute. Sometimes we need more control (when we do not know the name of the attribute in advance). For example, instance.attribute would become getattr(instance, attribute_name). Using this model, we can get the attribute by supplying the attribute_name as a string. … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)