How to implement an abstract class in Ruby

Just to chime in late here, I think that there’s no reason to stop somebody from instantiating the abstract class, especially because they can add methods to it on the fly. Duck-typing languages, like Ruby, use the presence/absence or behavior of methods at runtime to determine whether they should be called or not. Therefore your … Read more

When to use abstract classes?

Abstract classes are useful when you need a class for the purpose of inheritance and polymorphism, but it makes no sense to instantiate the class itself, only its subclasses. They are commonly used when you want to define a template for a group of subclasses that share some common implementation code, but you also want … Read more

What are the differences between abstract classes and interfaces in Java 8?

Interfaces cannot have state associated with them. Abstract classes can have state associated with them. Furthermore, default methods in interfaces need not be implemented. So in this way, it will not break already existing code, as while the interface does receive an update, the implementing class does not need to implement it. As a result … Read more

Why can’t we declare a std::vector?

You can’t instantiate abstract classes, thus a vector of abstract classes can’t work. You can however use a vector of pointers to abstract classes: std::vector<IFunnyInterface*> ifVec; This also allows you to actually use polymorphic behaviour – even if the class wasn’t abstract, storing by value would lead to the problem of object slicing.

How should I have explained the difference between an Interface and an Abstract class?

I will give you an example first: public interface LoginAuth{ public String encryptPassword(String pass); public void checkDBforUser(); } Suppose you have 3 databases in your application. Then each and every implementation for that database needs to define the above 2 methods: public class DBMySQL implements LoginAuth{ // Needs to implement both methods } public class … Read more