JavaScript第4章判断与和循环(revise)
总结
判断和循环
- 判断语句允许抉择接下来应该执行什么操作
- 比较操作符可以用来比较两个操作数
- 逻辑操作符允许把多个比较操作符合并在一起
- if…else语句允许在条件为true的时候运行一组代码,在条件为false的时候运行另一组代码
- switch语句允许比较一个值的多个可能结果(同样也提供了一个默认选项,用于不匹配任何结果)
- 数据类型可以从一种强制转换为另一种类型
- 所有的值可以视为真值或假值
- 有三种循环
Java第7章面向对象的几个基本原则
UML类图简介
UML(统一建模语言)
UML类图使用一个长方形描述一个类的主要构成
面向抽象原则
原因是为了迎合用户的需求而不影响具体类,那么就需要构建一个抽象类使其对具体类不再依赖,
package TextCourse;
//关于面向抽象
abstract class Geometry{ //抽象类用于扩展更多的子类
public abstract double getArea();
}
class Pillar { //类似于产品类
Geometry bottom; //声明抽象类变量
int height;
Pillar(){
}
Pillar(int height){
this.height = height;
}
public void getVolume(Geometry bottom){ //用抽象类的变量作为参数
System.out.println("体积是:" + height*bottom.getArea());
}
}
class Rectangle extends Geometry{ //抽象类的子类
int height;
int width;
Rectangle(){
}
Rectangle(int height,int width){ //自定义构造方法
this.height = height;
this.width = width;
}
@Override
public double getArea() { //对继承抽象类的方法进行重写
return height*width;
}
}
class Roundness extends Geometry{
int r;
Roundness(){
}
Roundness(int r){
this.r = r;
}
@Override
public double getArea() {
return Math.PI*r*r;
}
}
public class Example7_1 {
public static void main(String[] args) {
Pillar pillar = new Pillar(6);
pillar.getVolume(new Roundness(3));
pillar.getVolume(new Rectangle(4,5));
}
}
结果代码
"D:\IntelliJ IDEA 2019.3.3\jbr\bin\java.exe" "-javaagent:D:\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=56070:D:\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath D:\HelloWorld\out\production\HelloJava TextCourse.Example7_1
体积是:169.64600329384882
体积是:120.0
进程已结束,退出代码 0
开-闭原则
对扩展开放,对修改关闭
这句话的本质是指当一个设计中增加新的模块的时,不需要修改现有的模块
- 在给出一个设计时,应当首先考虑到用户需求的变化
- 将应对用户变化的部分设计为对扩展开放
- 而设计的核心部分是经过精心考虑之后确定下来的基本结构,这部分应当是对修改关闭
CET4P142
undertake
understanding
drill
force
skilled
nitrogen
merry
salary
commission
assembly
fog
fluid
jaw