我知道紧耦合和松耦合的区别,Java代码:谁能解释

我知道紧耦合和松耦合的区别,根据这篇文章:

我不明白的是它使用的例子。

对于松散耦合,Java 代码

 class Volume {
   public static void main(String args[]) {
        Cylinder b = new Cylinder(25, 25, 25);
           System.out.println(b.getVolume());

   }
}
final class Cylinder {
    private int volume;

    Cylinder(int length, int width, int height) {
             this.volume = length * width * height;
    }
    public int getVolume() {

             return volume;
    }
}

为了紧密耦合,Java 代码:

class Volume {
   public static void main(String args[]) {
        Cylinder b = new Cylinder(15, 15, 15);
           System.out.println(b.volume);

   }}
 class Cylinder {
   public int volume;
   Cylinder(int length, int width, int height) {
           this.volume = length * width * height;  }}

谁能解释第二个代码如何使两个类(体积和圆柱体)绑定在一起(紧密耦合)?或者是什么让第一个代码松耦合?谢谢。

© 版权声明
THE END
喜欢就支持一下吧
点赞38赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容