Is there more to an interface than having the correct methods

后端 未结 17 983
小鲜肉
小鲜肉 2020-11-22 13:37

So lets say I have this interface:

public interface IBox
{
   public void setSize(int size);
   public int getSize();
   public int getArea();
  //...and so          


        
17条回答
  •  再見小時候
    2020-11-22 14:26

    Don't forget that at a later date you can take an existing class, and make it implement IBox, and it will then become available to all your box-aware code.

    This becomes a bit clearer if interfaces are named -able. e.g.

    public interface Saveable {
    ....
    
    public interface Printable {
    ....
    

    etc. (Naming schemes don't always work e.g. I'm not sure Boxable is appropriate here)

提交回复
热议问题