美文网首页
无标题文章

无标题文章

作者: ae58a3ebbdaf | 来源:发表于2017-05-19 06:03 被阅读0次

    JavaScript 设计模式学习笔记二(共十七章)

    第二章 接口

    什么是接口

    接口提供了一种说明以一个对象应该具有哪些方法的手段。

    接口之利

    接口具有自我描述性,并能促进代码重用。有助于稳定不同类之间的通信方式。

    接口之弊

    JavaScript 的弱类型特定,使得它具有极强的语言表现力。而接口的使用则在一定程度上强化了类的作用,这降低了语言的灵活性。

    其他面向对象语言处理接口的方式

    java

    public interface DataOutput{
        void writeBoolean(boolean value) throws IOException;
        void writeChar(int value) throws IOException;
        void writeShort(int value) throws IOException;
        void writeInt(int value) throws IOException;
    }
    
    /*接口的实现*/
    public class DataOutputSteam extends filterDataOutputStream implements DataOutPut{
        public final void writeBoolean (boolean value) throws IOException{
            write(value ? 1 : 0 );
        }
    }
    
    

    php

    interface MyInterface{
        public function interfaceMethod($argumentOne,$argumentTwo);    
    }
    class MyClass implements MyInterface{
        public function interfaceMethod($argumentOne,$argumentTwo){
            return $argumentOne . $argumentTwo
        }
    }
    

    C#

    interface MyInterface{
        string interfaceMethod(string argumentOne,string argumentTwo);
    }
    class MyClass : MyInterface{
        public string interfaceMethod(string argumentOne,string argumentTwo){
            return argumentOne + argumentTwo;
        }
    }
    

    相关文章

      网友评论

          本文标题:无标题文章

          本文链接:https://www.haomeiwen.com/subject/rwiexxtx.html