二、工厂方法模式
1.动物管理系统的例子
首先,抽象的动物类和具体的动物实现类:
public interface Animal{
public void eat();
}
public class Tiger implements Animal
{
public void eat(){
sysout.out.println("老虎会吃");
};
...
分类:
其他好文 时间:
2014-07-22 00:07:33
阅读次数:
231
一、概念 当想要对已有的对象进行功能增强时,可以自定义类,将已有对象传入,基于现有的功能,并加强功能。 装饰类通常会通过构造方法接受被修饰的对象。 二、例子 class Person { public void eat(){ sysout(“I am eating”); } } class Pers...
分类:
其他好文 时间:
2014-07-22 00:04:35
阅读次数:
176
一、简单工厂模式
1.动物管理系统的例子
public interface Animal{
public void eat();
}
public class Tiger implements Animal
{
public void eat(){
sysout.out.println("老虎会吃");
};
public void run(){
sysou...
分类:
其他好文 时间:
2014-07-20 23:03:30
阅读次数:
195
Description
Problem E
Eat or not to Eat?
Input: Standard Input
Output: Standard Output
A young farmer has N cows, but they produced really really a very very small amount of milk. John ca...
分类:
其他好文 时间:
2014-07-19 08:09:15
阅读次数:
296
public class TestThis { private String name; void eat(String name){ //String food;//局部变量在使用时必须初始化,否则会报错 error String food = "apple"; //right Syste...
分类:
其他好文 时间:
2014-07-16 17:01:11
阅读次数:
169
不多说 NOI2001食物链核心就是并查集,并查集数组中存0 1 2 3 表示未分营养级 A B C然后再一个个恶心的判断....inline bool Union(int x,int y,int D){ int a=find(x), b=find(y); if(a==b){ ...
分类:
其他好文 时间:
2014-07-13 08:31:54
阅读次数:
197
经验:"public继承"意味 is-a。适用于 base classes 身上的每一件事情一定也适用于 derived classes 身上,
因为每一个 derived classes 身上,因为每一个 derived class 对象也都是一个 base class 对象。
示例:
class Person {...};
class Student: public Person {...};
void eat(const Person &p); //任何人都会吃
void study(const ...
分类:
编程语言 时间:
2014-07-12 21:18:25
阅读次数:
230
我的理解是:通过继承实现的不同对象调用相同的方法,表现出不同的行为,称之为多态. 1: OverRide 实现多态 1 public class Animal 2 { 3 public virtual void Eat() 4 { 5 ...
分类:
其他好文 时间:
2014-07-07 00:44:06
阅读次数:
283
call_user_func ( callback $function [, mixed $parameter [, mixed $... ]]
)
调用第一个参数所提供的用户自定义的函数。
返回值:返回调用函数的结果,或FALSE。
example :
Php代码
function eat($fruit) //参数可以为多个
{...
分类:
Web程序 时间:
2014-07-06 09:11:06
阅读次数:
246
Problem Statement
Rabbits often feel hungry, so when they go out to eat carrots, they jump as quickly as possible.
Initially, rabbit Hanako stands at position init. From position x, she ...
分类:
其他好文 时间:
2014-07-02 17:02:04
阅读次数:
201