خرید بک لینک

Vote count: 2

I have some general questions regarding interface usage:

  1. What is the advantages in creating interface for each object class ?
  2. Should interface only contains 'getter' methods?
  3. Why not also the setter?
  4. Why should I create for each object class an interface? Will it served me in the JUnit tests?

For example :

    public interface Animal {
      public getVoice();
      public String getName();
    }

public class Dog implements Animal {
   private String name;

   public getVoice(){
      System.out.println("Brrr");
   }
   public String getName(){
      retu this.name;
   }
   public void setName(String name){
      this.name = name;
  }

}

Thanks

asked 9 mins ago

1 Answer

Vote count: 1

What is the advantages in creating interface for each object class ?

There is no advantage at all. That is not what Interfaces are for.

Should interface only contains 'getter' methods? Why not also the setter?

As long as it is method, interfaces doesn't care about their functional behaviour.

Why should I create for each object class an interface?

Again, that is not the purpose of interface. Consider that as Redundant.

answered 7 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 5 خرداد 1395 ساعت: 23:40

صفحه بندی