Type List vs type ArrayList in Java

Almost always List is preferred over ArrayList because, for instance, List can be translated into a LinkedList without affecting the rest of the codebase. If one used ArrayList instead of List, it’s hard to change the ArrayList implementation into a LinkedList one because ArrayList specific methods have been used in the codebase that would also require restructuring. You can read about the List implementations here. You may start with an ArrayList, but soon after discover that … Read more

Java Pass Method as Parameter

Edit: as of Java 8, lambda expressions are a nice solution as other answers have pointed out. The answer below was written for Java 7 and earlier… Take a look at the command pattern. Edit: as Pete Kirkham points out, there’s another way of doing this using a Visitor. The visitor approach is a little more involved – your nodes all need to be … Read more

Multiple Inheritance in C#

Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. C# and the .net CLR have not implemented MI because they have not concluded how it would inter-operate between C#, VB.net and the other languages yet, … Read more

Implements vs extends: When to use? What’s the difference?

extends is for extending a class. implements is for implementing an interface The difference between an interface and a regular class is that in an interface you can not implement any of the declared methods. Only the class that “implements” the interface can implement the methods. The C++ equivalent of an interface would be an abstract class (not EXACTLY the same … Read more

Generic Interface

Here’s one suggestion: Because of type erasure any class will only be able to implement one of these. This eliminates the redundant method at least. It’s not an unreasonable interface that you’re proposing but I’m not 100% sure of what value it adds either. You might just want to use the standard Callable interface. It doesn’t support … Read more

Interfaces vs Types in TypeScript

Original Answer (2016) As per the (now archived) TypeScript Language Specification: Unlike an interface declaration, which always introduces a named object type, a type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types. The specification goes on to mention: Interface types have many similarities to type aliases for object type literals, … Read more

how to implement Interfaces in C++?

C++ has no built-in concepts of interfaces. You can implement it using abstract classes which contains only pure virtual functions. Since it allows multiple inheritance, you can inherit this class to create another class which will then contain this interface (I mean, object interface 🙂 ) in it. An example would be something like this … Read more