zoukankan      html  css  js  c++  java
  • [Java] TinkingInOO 设计模式热身--面向对象

    Driver
    public class Driver {
    	private String name;
    	
    	
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public void drive(Vihecle v) {
    		v.go(new Address("东北"));
    	}
    	
    	public void drive(Car c, Address dest) {
    		c.go(dest);
    	}
    }
    
    Address
    public class Address {
    	private String name;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public Address(String name) {
    		super();
    		this.name = name;
    	}
    	
    }
    Vihecle
    public abstract class Vihecle {
    	public abstract void go(Address dest);
    }
    
    //Movable go
    Car
    public class Car extends Vihecle {
    	public void go(Address dest) {
    		System.out.println("一路哼着歌,冒着烟,去了" + dest.getName());
    	}
    }
    
    Broom
    public class Car extends Vihecle {
    	public void go(Address dest) {
    		System.out.println("一路哼着歌,冒着烟,去了" + dest.getName());
    	}
    }
    
    Test
    public class Test {
    	public static void main(String[] args) {
    		Driver d = new Driver();
    		d.setName("老张");
    		d.drive(new Broom());
    	}
    }	
    相关输出 :
    一路扫着土去了东北
    
    one hour to OO 一小时OO教程
    Next :
    谈谈工具
     @1, 思想是战略高度的东西
     @2, 工具是战术高度的东西
     工具的学习:
        (1), 敢用
        (2), 勤用

    项目背景 :东北人

    封装继承多态
     * 追求完美是一种缺陷
    多态
     (1), 核心中的核心
     (2), 可扩展性(Extensibility)
    注意 : 
     有这类事物可以作为抽象类。事物的特性设计成接口。






  • 相关阅读:
    微人事项目-mybatis-持久层
    通过外键连接多个表
    springioc
    Redis 消息中间件 ServiceStack.Redis 轻量级
    深度数据对接 链接服务器 数据传输
    sqlserver 抓取所有执行语句 SQL语句分析 死锁 抓取
    sqlserver 索引优化 CPU占用过高 执行分析 服务器检查
    sql server 远程备份 bak 删除
    冒泡排序
    多线程 异步 beginInvoke EndInvoke 使用
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786551.html
Copyright © 2011-2022 走看看