Coupling and cohesion

Coupling Loose: You and the guy at the convenience store. You communicate through a well-defined protocol to achieve your respective goals – you pay money, he lets you walk out with the bag of Cheetos. Either one of you can be replaced without disrupting the system. Tight: You and your wife. Cohesion Low: The convenience … 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

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

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

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

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

tech