The Stack Overflow podcast is back! Listen to an interview with our new CEO.
3 added 249 characters in body
source | link

A rule of thumb is that:

  • Interfaces providedefine the public API (contract) or a certain functionality if you will,
  • Abstract classes (may) provide a private API (for extended classes to use), such as shared functionality.

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; you don't have to specify an interface twice if the ancestor already implements it, because the interpreter will throw an error if you try to break the contract.

This would only make sense if the child class implements another interface altogether. And this is a strength of interfaces; since you're defining a piece of functionality rather than a specific implementation, you can make any class implement any interface if you wanted to. This is a great help when writing mock classes for testing.

A rule of thumb is that:

  • Interfaces provide the public API (contract)
  • Abstract classes (may) provide a private API (for extended classes to use), such as shared functionality

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; you don't have to specify an interface twice if the ancestor already implements it, because the interpreter will throw an error if you try to break the contract.

This would only make sense if the child class implements another interface altogether.

A rule of thumb is that:

  • Interfaces define the public API (contract) or a certain functionality if you will,
  • Abstract classes (may) provide a private API (for extended classes to use), such as shared functionality.

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; you don't have to specify an interface twice if the ancestor already implements it, because the interpreter will throw an error if you try to break the contract.

This would only make sense if the child class implements another interface altogether. And this is a strength of interfaces; since you're defining a piece of functionality rather than a specific implementation, you can make any class implement any interface if you wanted to. This is a great help when writing mock classes for testing.

2 added 183 characters in body
source | link

A rule of thumb is that:

  • Interfaces provide the public API (or blueprintcontract)
  • Abstract classes (may) provide a private API (for extended classes to use), such as shared functionality

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; sometimesyou don't have to specify an interface defines a subset of functionality, so thentwice if the ancestor already implements it, because the interpreter will throw an error if you try to break the contract. would

This would only make a differencesense if the child class implements another interface altogether.

A rule of thumb is that:

  • Interfaces provide the public API (or blueprint)
  • Abstract classes (may) provide a private API (for extended classes to use)

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; sometimes an interface defines a subset of functionality, so then it would make a difference.

A rule of thumb is that:

  • Interfaces provide the public API (contract)
  • Abstract classes (may) provide a private API (for extended classes to use), such as shared functionality

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; you don't have to specify an interface twice if the ancestor already implements it, because the interpreter will throw an error if you try to break the contract.

This would only make sense if the child class implements another interface altogether.

1
source | link

A rule of thumb is that:

  • Interfaces provide the public API (or blueprint)
  • Abstract classes (may) provide a private API (for extended classes to use)

So i am confused which methods should go where

If a method should be part of the public API, add it to the interface and update dependencies where necessary (i.e. Abstract and / or Generic class).

Otherwise, implement the method as high up as is needed based on how generic or specific it is.

Sometimes i see class A extends Abstractuserclass and sometimes class A extends Abstractuserclass implements useraInterface. what is the difference if Abstractclass already implements Userinterface

There's no difference in that case; sometimes an interface defines a subset of functionality, so then it would make a difference.