When to use an interface instead of an abstract class and vice versa?

I wrote an article about that: Abstract classes and interfaces Summarizing: When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is. When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object … Read more

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

Why can’t I define a static method in a Java interface?

Java 8 permits static interface methods With Java 8, interfaces can have static methods. They can also have concrete instance methods, but not instance fields. There are really two questions here: Why, in the bad old days, couldn’t interfaces contain static methods? Why can’t static methods be overridden? Static methods in interfaces There was no … Read more

When to use: Java 8+ interface default method, vs. abstract method

There’s a lot more to abstract classes than default method implementations (such as private state), but as of Java 8, whenever you have the choice of either, you should go with the defender (aka. default) method in the interface. The constraint on the default method is that it can be implemented only in the terms … Read more

Type List vs type ArrayList in Java [duplicate]

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 … Read more

Difference between abstract class and interface in Python

What you’ll see sometimes is the following: class Abstract1: “””Some description that tells you it’s abstract, often listing the methods you’re expected to supply.””” def aMethod(self): raise NotImplementedError(“Should have implemented this”) Because Python doesn’t have (and doesn’t need) a formal Interface contract, the Java-style distinction between abstraction and interface doesn’t exist. If someone goes through … Read more

C# Interfaces. Implicit implementation versus Explicit implementation

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as: public void CopyTo(Array array, int index) { throw new NotImplementedException(); } and explicitly … Read more

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