面向对象面向过程
编程技术  /  houtizong 发布于 3年前   227
package bigDemo.ObjectOriented;/** * 大象类 * * @Description * @author FuJianyong * 2015-7-1下午05:47:11 */public class Elephant { private String name; public Elephant(String name){this.name = name;}public String getName() {return name;}}
package bigDemo.ObjectOriented;/** * 冰箱类 * * @Description * @author FuJianyong * 2015-7-1下午05:39:05 */public class IceBox {private String name;public void open(People people){System.out.println(people.getName() + "把" + this.name + "打开");}public void close(People people){System.out.println(people.getName() + "把" + this.name + "关闭");}public IceBox(String name) {this.name = name;}public String getName() {return name;}}
package bigDemo.ObjectOriented;/** * 人类 * * @Description * @author FuJianyong * 2015-7-1下午05:39:15 */public class People { private String name;/** * 描述人的动作 */private String action;public void openIceBox(IceBox iceBox){iceBox.open(this);//this表示调用此方法的对象(当前对象)}public void pushElephant(Elephant elephant, IceBox iceBox){System.out.println(this.getName() + "把" + elephant.getName() + this.action + iceBox.getName());}public void closeIceBox(IceBox iceBox){iceBox.close(this);}public People(String name, String action){this.name = name;this.action = action;}public String getName() {return name;}}
package bigDemo.ObjectOriented;/** * 面向对象实现装大象进冰箱 * * @Description * @author FuJianyong * 2015-6-30上午10:14:26 */public class ObjectOriented {public static void main(String[] args) {final IceBox iceBox = new IceBox("冰箱");final Elephant elephant = new Elephant("大象");final People people = new People("小明", "推进"); people.openIceBox(iceBox); people.pushElephant(elephant, iceBox); people.closeIceBox(iceBox);}}
package bigDemo.ObjectOriented;/** * 牛奶类 * * @author FuJianyong * 2015-7-2下午10:05:10 */public class Milk {private String name; public Milk(String name){this.name = name;}public String getName() {return name;}}
public void pushMilk(Milk milk, IceBox iceBox){System.out.println(this.getName() + "把" + milk.getName() + this.action + iceBox.getName());}
package bigDemo.ObjectOriented;/** * 面向对象实现装大象进冰箱 * * @Description * @author FuJianyong * 2015-6-30上午10:14:26 */public class ObjectOriented {public static void main(String[] args) {final IceBox iceBox = new IceBox("冰箱");final Milk milk = new Milk("牛奶");final People people = new People("小白", "放进"); people.openIceBox(iceBox); people.pushMilk(milk, iceBox); people.closeIceBox(iceBox);}}
package bigDemo.ProcessOriented;/** * 面向过程实现装大象进冰箱 * @Description * @author FuJianyong * 2015-7-1下午05:08:47 */public class ProccessOriented {public void openIceBox(String people, String elephant, String iceBox){System.out.println(people + "打开冰箱");pushElephant(elephant, iceBox);}public void pushElephant(String elephant, String iceBox){System.out.println("装" + elephant + "进" + iceBox);closeIceBox(iceBox);}public void closeIceBox(String iceBox){System.out.println("关闭" + iceBox);}public static void main(String[] args) { new ProccessOriented().openIceBox("小明", "大象", "冰箱");}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接