Should I use public or private variables?

private data members are generally considered good because they provide encapsulation. Providing getters and setters for them breaks that encapsulation, but it’s still better than public data members because there’s only once access point to that data. You’ll notice this during debugging. If it’s private, you know you can only modify the variable inside the … Read more

Does the Bridge Pattern decouples an abstraction from implementation?

BridgePattern decouples an abstraction from its implementation. Abstraction and Implementation can vary independently since the concrete class does not directly implement Abstraction ( interface) Implementation never refers Abstraction. Abstraction contains Implementation interface as a member (through composition). Coming back to your question regarding the example code in [journaldev][4] article : Shape is Abstraction Triangle is … Read more

What does the quote “An extra level of indirection solves every problem” mean? [closed]

Generally it means that by increasing the level of abstraction one can make the problem easier to understand/resolve. Be careful with your abstractions though, the full quote at least as I heard it is, “You can solve every problem with another level of indirection, except for the problem of too many levels of indirection”.

What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

Interfaces are excellent when you want to create something like it: using System; namespace MyInterfaceExample { public interface IMyLogInterface { //I want to have a specific method that I’ll use in MyLogClass void WriteLog(); } public class MyClass : IMyLogInterface { public void WriteLog() { Console.Write(“MyClass was Logged”); } } public class MyOtherClass : IMyLogInterface … 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