When to use interfaces or abstract classes? When to use both?

As a first rule of thumb, I prefer abstract classes over interfaces, based on the .NET Design Guidelines. The reasoning applies much wider than .NET, but is better explained in the book Framework Design Guidelines. The main reasoning behind the preference for abstract base classes is versioning, because you can always add a new virtual … Read more

Diamond Problem

Its not the same problem. In the original problem, the overriden method can be called from A. In your problem this can’t be the case because it does not exist. In the diamond problem, the clash happens if class A calls the method Foo. Normally this is no problem. But in class D you can … Read more

Where and how is the term used “wrapper” used in programming, and what does it help to do?

The term ‘wrapper’ gets thrown around a lot. Generally its used to describe a class which contains an instance of another class, but which does not directly expose that instance. The wrapper’s main purpose is to provide a ‘different’ way to use wrapped object (perhaps the wrapper provides a simpler interface, or adds some functionality). … Read more

Can you write any algorithm without an if statement?

Smalltalk, which is considered as a “truly” object oriented language, has no “if” statement, and it has no “for” statement, no “while” statement. There are other examples (like Haskell) but this is a good one. Quoting Smalltalk has no “if” statement: Some of the audience may be thinking that this is evidence confirming their suspicions … Read more

What is high level modules and low level modules.?

High level module is the interface / abstraction that will be consumed directly by the presentation layer. Low level on the other hand are bunch of small modules (subsystems) help the high level do their work. Example below is the high level module. I have excluded the dependency constructor injection for shorter sample. public class … Read more

What’s the difference between Polymorphism and Multiple Dispatch?

Polymorphism is the facility that allows a language/program to make decisions during runtime on which method to invoke based on the types of the parameters sent to that method. The number of parameters used by the language/runtime determines the ‘type’ of polymorphism supported by a language. Single dispatch is a type of polymorphism where only … Read more

When is a class too big? [closed]

Step one is to adhere to the Single Responsibility Principle. If you can’t say in one sentence what your class does, then it probably does too much. Once you’ve narrowed that down, I don’t know that the number of methods really matters as long as your methods don’t do too much.

Why avoid subtyping?

Types determine the granularity of composition, i.e. of extensibility. For example, an interface, e.g. Comparable, that combines (thus conflates) equality and relational operators. Thus it is impossible to compose on just one of the equality or relational interface. In general, the substitution principle of inheritance is undecidable. Russell’s paradox implies that any set that is … Read more

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