Tue May 9 11:09:00 UTC 2023 inscode

上级 d1cfa7d4
class SingleResponsibility1 {
public static void main(String[] args) {
Vehicle vehicle = new Vehicle();
vehicle.run("摩托车");
vehicle.run("汽车");
vehicle.run("飞机");
}
}
/**
* 交通工具类
* 方式1
* 1、在方式1的run方法中,违反了单一职责原则
* 2、解决的方案非常简单,根据交通工具运行方式不同,分解成不同的类即可
*/
class Vehicle {
public void run(String vehicle){
System.out.println(vehicle + " 在公路上运行。。。。。");
}
}
public class Main { class Main {
public static void main(String[] args) { public static void main(String[] args) {
Vehicle vehicle = new Vehicle(); System.out.println("Hello Word!!");
vehicle.run("摩托车");
vehicle.run("汽车");
vehicle.run("飞机");
}
}
/**
* 交通工具类
* 方式1
* 1、在方式1的run方法中,违反了单一职责原则
* 2、解决的方案非常简单,根据交通工具运行方式不同,分解成不同的类即可
*/
class Vehicle {
public void run(String vehicle){
System.out.println(vehicle + " 在公路上运行。。。。。");
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册