![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
面向对象设计思想,优秀的类设计。 10
面向对象设计强调类细节实现的封装,那么细节部分的代码如何设计,才能让这个类更优秀,更易用,更强大?...
面向对象设计强调类细节实现的封装,那么细节部分的代码如何设计,才能让这个类更优秀,更易用,更强大?
展开
2个回答
展开全部
在方法上要保持功能的单一,这样就可以可以最大化的实现重用。
方法和变量名,要见名知意(不要用简写,长点无所谓),这样就可以少些注解。
代码要朝着人更能理解的方式去写。(在不影响性能的情况下);
个人拙见!! 希望能帮到你
方法和变量名,要见名知意(不要用简写,长点无所谓),这样就可以少些注解。
代码要朝着人更能理解的方式去写。(在不影响性能的情况下);
个人拙见!! 希望能帮到你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Vehicle {
private int wheels;
private double weight;
public Vehicle()
public Vehicle(int w, double we) {
this.weight = we;
this.wheels = w;
}
public int getWheels() {
return wheels;
}
public void setWheels(int wheels) {
this.wheels = wheels;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String showMe(){
return wheels +", " + weight;
}
}
class Car extends Vehicle {
private int loader;
public Car()
public Car(int wh, double we, int l) {
super(wh, we);
this.loader = l;
}
public int getLoader() {
return loader;
}
public void setLoader(int loader) {
this.loader = loader;
}
public String showMe(){
return super.showMe()+", "+loader;
}
}
class Truck extends Car {
private double payLoader;
public Truck() {}
public Truck(double p){
this.payLoader = p;
}
public double getPayLoader() {
return payLoader;
}
public void setPayLoader(double payLoader) {
this.payLoader = payLoader;
}
public String showMe(){
return super.showMe()+", "+payLoader;
}
}
private int wheels;
private double weight;
public Vehicle()
public Vehicle(int w, double we) {
this.weight = we;
this.wheels = w;
}
public int getWheels() {
return wheels;
}
public void setWheels(int wheels) {
this.wheels = wheels;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String showMe(){
return wheels +", " + weight;
}
}
class Car extends Vehicle {
private int loader;
public Car()
public Car(int wh, double we, int l) {
super(wh, we);
this.loader = l;
}
public int getLoader() {
return loader;
}
public void setLoader(int loader) {
this.loader = loader;
}
public String showMe(){
return super.showMe()+", "+loader;
}
}
class Truck extends Car {
private double payLoader;
public Truck() {}
public Truck(double p){
this.payLoader = p;
}
public double getPayLoader() {
return payLoader;
}
public void setPayLoader(double payLoader) {
this.payLoader = payLoader;
}
public String showMe(){
return super.showMe()+", "+payLoader;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询