java - Dependency Injection: Difference between loose coupling mechanisms based on interface and class? -


suppose, have 2 configurations.

first one:

interface {     ... }  class implements {     ... }  class b implements {     ... }  class component {     i;         component (i i) {         this.i = i;     } } 

second one:

class c {     ... }  class extends c {     ... }  class b extends c {     ... }  class component {     c c;         component (c c) {         this.c = c;     } } 

what in difference between 2 configurations using 2 different loose coupling mechanisms (based on interface , based on class)?

why should need use interface on class?

an object can implements multiple interfaces can extends 1 class, user of loose coupled library may not able extends class.

when extends, incorporate code of superclass yours, there no code incorporate implements better suited.

finally not same paradigm, when write "b extends a" "i a, same things, can make other things". when write "b implements a" "i b, can treat me a".

long story short, practical reason first.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -