What is an anti-pattern?

Anti-patterns are certain patterns in software development that are considered bad programming practices. As opposed to design patterns which are common approaches to common problems which have been formalized and are generally considered a good development practice, anti-patterns are the opposite and are undesirable. For example, in object-oriented programming, the idea is to separate the … Read more

Why do we use Interface? Is it only for Standardization? [closed]

Purposes of Interfaces create loosely coupled software support design by contract (an implementor must provide the entire interface) allow for pluggable software allow different objects to interact easily hide implementation details of classes from each other facilitate reuse of software Analogy 1: Much like the US space shuttle, Russian Soyuz spacecraft and Chinese Shenzhou 5 … Read more

Constructors vs Factory Methods [closed]

Ask yourself what they are and why do we have them. They both are there to create instance of an object. ElementarySchool school = new ElementarySchool(); ElementarySchool school = SchoolFactory.Construct(); // new ElementarySchool() inside No difference so far. Now imagine that we have various school types and we want to switch from using ElementarySchool to … 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

What does “program to interfaces, not implementations” mean?

Interfaces are just contracts or signatures and they don’t know anything about implementations. Coding against interface means, the client code always holds an Interface object which is supplied by a factory. Any instance returned by the factory would be of type Interface which any factory candidate class must have implemented. This way the client program … Read more

When should you use a class vs a struct in C++?

The differences between a class and a struct in C++ is: struct members and base classes/structs are public by default. class members and base classes/struts are private by default. Both classes and structs can have a mixture of public, protected and private members, can use inheritance and can have member functions. I would recommend you: … Read more