zoukankan      html  css  js  c++  java
  • js原生设计模式——13桥接模式(相同业务逻辑抽象化处理的职责链模式)

    桥接模式之多元化类之间的实例化调用实例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>桥接模式之多元化类之间的实例化调用</title>
        <script type="text/javascript">
        //多维类的声明和调用(有点像类职责链模式)
        //这些功能类也可看作是功能模块的抽象层
        //运动类模块
        var Speed = function(x,y){
            this.x = x;
            this.y = y;
        }
        Speed.prototype.run = function(){
            console.log('跑起来');
        }
        //着色类模块
        function Color(cl){
            this.color = cl;
        }
        Color.prototype.draw = function(){
            console.log('绘制颜色');
        }
        //变形类模块
        function Shape(sp){
            this.shape = sp;
        }
        Shape.prototype.change = function(){
            console.log('改变形状');
        }
        //说话类模块
        function Speek(wd){
            this.word = wd;
        }
        Speek.prototype.say = function(){
            console.log('我可以说话');
        }
        //具体实现层的几个类,在功能上调用上面的抽象类
        //接下来我们想创建一个球类,可以运动,可以着色
        function Ball(x,y,c){
            this.speed = new Speed(x,y);//实现运动单元
            this.color = new Color(c);//实现着色单元
        }
        Ball.prototype.init = function(){
            this.speed.run();  //实现运动方法
            this.color.draw(); //实现着色方法
        }
        //同样我们想创造一个人类,他可以运动可以说话
        function Person(x,y,f){
            this.speed = new Speed(x,y);
            this.speek = new Speek(f);
        }
        Person.prototype.init = function(){
            this.speed.run();
            this.speek.say();
        }
        //最后我们想创造一个精灵类,他可以运动可以说话可以着色可以变形
        function Spirite(x,y,c,f,s){
            this.speed = new Speed(x,y);
            this.speek = new Speek(f);
            this.color = new Color(c);
            this.shape = new Shape(s);
        }
        Spirite.prototype.init = function(){
            this.speed.run();
            this.speek.say();
            this.color.draw();
            this.shape.change();
        }
        //测试用例
        var p = new Person(10,12,16);
        p.init();
        //本例已经通过验证
        </script>
    </head>
    <body>
    </body>
    </html>

  • 相关阅读:
    hive报错 java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default
    使用Beeline连接Hive
    hive报错 root is not allowed to impersonate root (state=08S01,code=0)
    hive报错 Could not open client transport with JDBC Uri: jdbc:hive2://node01:10000/default:java.net.ConnectException refused
    excel快速删除空值单元格,数据上移
    FineBI 图表选择
    数据库连接池大小设置?
    工作中有待留❤️积累的一些经验
    内存包括随机存储器(RAM),只读存储器(ROM),以及高速缓存(CACHE)。RAM最重要
    我自己ood的复习思路:抄
  • 原文地址:https://www.cnblogs.com/koleyang/p/5039457.html
Copyright © 2011-2022 走看看