身上发热是什么原因| 什么高什么下| 吃什么补心脏供血不足| 火麻是什么植物| 单纯疱疹病毒吃什么药| ih医学上是什么意思| 脚拇指外翻是什么原因造成的| 有什么国家| 妯娌是什么意思| 眼睛有点模糊是什么原因| 女性长期缺维d会带来什么病| 宫颈出血是什么症状| 萌萌哒是什么意思| 胃属于什么科室| 917是什么意思| 闭经吃什么药| 可拉明又叫什么| 什么是业障| 腺肌症是什么症状| 氯低是什么原因| 93年的属什么| 美国的国歌是什么| 护理专业出来能干什么| 梦见水是什么征兆| 遇见是什么意思| 吃生葵花籽有什么好处和坏处吗| 艾灰有什么作用和功效| 中耳炎挂什么科| 维生素d什么牌子的好| 女人左眼跳是什么预兆| 什么是轻断食| 无精是什么原因造成的| 丝瓜不能和什么食物一起吃| 嗯呢是什么意思| 嘴唇一圈发黑是什么原因造成的| 社论是什么| isis是什么组织| 宝批龙是什么意思| 虾仁不能和什么食物一起吃| 五海瘿瘤丸主要治什么病| 类风湿关节炎吃什么药效果好| 火把节什么时候| 宝宝肠炎吃什么药| 业力是什么意思| 毛骨悚然是什么意思| 4.22是什么星座| 6月18日是什么节日| 三周年祭奠有什么讲究| 10月出生的是什么星座| 富不过三代是什么意思| 为什么不能在一起| 手指甲发紫是什么原因| 不愁吃穿是什么生肖| 肾积水有什么危害| 男怕穿靴女怕戴帽什么意思| 做梦梦到蟒蛇是什么征兆| 漠漠什么意思| 痛风喝什么茶最好| 377是什么| 腱鞘炎吃什么药好| 乙肝五项45阳性是什么意思| 失眠吃什么药| 梅毒螺旋体抗体阴性是什么意思| 什么帽子不能戴| 陈皮泡水喝有什么作用| 薄谷开来为什么杀人| 玉五行属性是什么| 水漂是什么意思| 人又不人鬼不鬼是什么生肖| 什么是发物| 什么姿势最深| baumwolle是什么面料| 气虚的人适合什么运动| 身上痣多是什么原因| 考科目二紧张吃什么药| 吃芒果不能吃什么| hvp是什么病毒| 拌嘴是什么意思| ghz是什么单位| 气胸叩诊呈什么音| 头发发黄是什么原因造成的| 吃什么药可以延长时间| 长痘痘擦什么药膏好| 8月13号什么星座| 荆芥的别名叫什么| 牛油果是什么味道的| 日晡潮热是什么意思| hpv是什么东西| 青春痘用什么药膏擦最好呢| creative是什么意思| 向日葵花语是什么| 灵芝有什么功效| dickies是什么牌子| 预估是什么意思| 脸过敏要注意什么| 计算机二级什么时候考| 什么动作可以提高性功能| 永浴爱河是什么意思| 化疗前吃什么补充营养| 心脏彩超能检查出什么| 耳朵红热是什么原因| 夏季有什么花| 口腔溃疡为什么是白色的| 身份证后4位代表什么| 法益是什么意思| 什么是埋线减肥| 口干嗓子干是什么原因| 什么是hpv病毒| 有什么办法| 草菅人命是什么意思| 吃什么排气| 打完除皱针注意事项有什么| 刘强东开什么车| 老打瞌睡犯困是什么原因| 蜕膜是什么| 中耳炎吃什么药效果比较好| 绿心黑豆有什么功效| 张国立的老婆叫什么名字| 欲加之罪何患无辞是什么意思| 纳豆什么味道| 火象是什么意思| 咳嗽嗓子疼吃什么药| rf是什么意思| 头加一笔是什么字| 肚子痛看什么科| 为什么有的| 精气是什么意思| 妇检tct是什么检查| 见不得别人好是什么心理| 卵巢囊肿是什么| 为什么天天做梦| 儿童急性肠胃炎吃什么药| 一月九号是什么星座| 常吃南瓜有什么好处和坏处| 什么鱼吃泥鳅| 什么是红肉| 后续是什么意思| wilson是什么意思| 空腹吃柿子有什么危害| 黄皮是什么| 偏激是什么意思| 肌肉损伤吃什么药| 金银花不能和什么一起吃| 一阴一阳是什么生肖| 什么是体脂率| 户口本可以干什么坏事| 肺部条索灶是什么意思| 七月与安生讲的是什么| 为什么射不出来| 火韦是什么字| 电压mv是什么意思| 观音菩萨属什么生肖| 辛弃疾字什么号什么| 姓陆的女孩取什么名字好| 安全生产职责是什么| 乳铁蛋白对宝宝有什么好处| 吉士粉是什么东西| elite是什么意思| 大师是什么意思| 精子是什么样的| 腱鞘炎吃什么药| 宫腔镜检查后需要注意什么| 儿童热伤风吃什么药| 学生吃什么补脑子增强记忆力最快| 手抽筋是什么原因引起的| 什么样的小溪| 公章是什么样的| 地中海贫血携带者是什么意思| 静脉曲张不治疗会有什么后果| 劳改犯是什么意思| 过敏性紫癜看什么科| 脚酸是什么原因引起的| crs是什么意思| 眼睛肿痛什么原因| 奔富红酒属于什么档次| 安全期是什么| 什么的樱桃| 置换是什么意思| 勃起不够硬吃什么药| 夏天的诗句有什么| 血热皮肤瘙痒吃什么药| 上皮细胞高是什么原因| 新奇的什么| 抚琴是什么意思| 豆蔻年华什么意思| 升米恩斗米仇是什么意思| 阴影是什么意思| 什么病误诊为帕金森| 大拇指戴戒指是什么意思| 新生儿什么时候吃ad| 判处死刑缓期二年执行是什么意思| 血清是什么意思| 坐月子什么不可以吃| 鸡精和味精有什么区别| 坐月子不能吃什么| sandisk是什么牌子| 一个虫一个合读什么| 黄瓜为什么苦| 高危hpv阳性是什么意思| ferragamo是什么牌子| 指甲有竖纹吃什么药| 骆驼是什么牌子| 漂洋过海是什么生肖| 眼睛晶体是什么| ad和d3有什么区别| 圣女果是什么水果| 属什么生肖| 黄芪什么功效| 时柱代表什么| 固执是什么意思| 变形虫是什么生物| 赵构为什么杀岳飞| 6月6日是什么星座| 爸爸生日送什么礼物| 什么的小莲蓬| 石榴红是什么颜色| 过期橄榄油有什么用途| 基佬是什么意思| 肾主骨是什么意思| 咳嗽有黄痰吃什么消炎药| 倒霉是什么意思| 肠胃不舒服吃什么| 脚肿什么病| 七六年属什么生肖| 身上长小红点是什么原因| 流清水鼻涕是什么感冒| 三言两语是什么生肖| 民营和私营有什么区别| 飞蚊症是什么原因引起的| 下巴两边长痘痘是什么原因| 大便蛋花状是什么原因| 寂寞是什么意思| 一什么人家| 农历六月初十是什么日子| 脑白质是什么病| 头昏脑胀吃什么药| 潮热盗汗是什么意思| 铁皮石斛有什么功效| 红颜什么意思| 起床眼睛肿是什么原因| 初中什么时候开学| 血常规异常是什么意思| 私处变黑是什么原因| 什么主食含糖量低| 中药为什么要热着喝| editor是什么意思| 瑞五行属什么| 扶他林是什么药| 儿童坐动车需要带什么证件| 莆田系是什么意思啊| 血糖高是什么病| 肝内强回声是什么意思| 酚氨咖敏片的别名叫什么| 脾胃虚吃什么好| 尿酸高喝什么| 飞蚊症是什么症状| 两横一竖是什么字| 什么瓜| 鼓包是什么意思| 14年是什么年| 占有欲强什么意思| 黄帝内经讲的什么| 鸡肠炎用什么药效果好| 头疼是因为什么| 百度Jump to content

哈登用撒盐动作庆祝引歌手Lil B不满:小心诅咒

From Wikipedia, the free encyclopedia
百度 所以,长途跋涉后应先适当休息再进行性生活。

In software engineering, the servant pattern defines an object used to offer some functionality to a group of classes without defining that functionality in each of them. A Servant is a class whose instance (or even just class) provides methods that take care of a desired service, while objects for which (or with whom) the servant does something, are taken as parameters.

Description and simple example

[edit]

Servant is used for providing some behavior to a group of classes. Instead of defining that behavior in each class - or when we cannot factor out this behavior in the common parent class - it is defined once in the Servant.

For example: we have a few classes representing geometric objects (rectangle, ellipse, and triangle). We can draw these objects on some canvas. When we need to provide a “move” method for these objects we could implement this method in each class, or we can define an interface they implement and then offer the “move” functionality in a servant. An interface is defined to ensure that serviced classes have methods that servant needs to provide desired behavior. If we continue in our example, we define an Interface “Movable” specifying that every class implementing this interface needs to implement method “getPosition” and “setPosition”. The first method gets the position of an object on a canvas and second one sets the position of an object and draws it on a canvas. Then we define a servant class “MoveServant”, which has two methods “moveTo(Movable movedObject, Position where)” and moveBy(Movable movedObject, int dx, int dy). The Servant class can now be used to move every object which implements the Movable. Thus the “moving” code appears in only one class which respects the “Separation of Concerns” rule.

Two ways of implementation

[edit]

There are two ways to implement this design pattern:

Figure 1: User uses servant to achieve some functionality and passes the serviced objects as parameters.
Figure 2: User requests operations from serviced instances, which then asks servant to do it for them.
  1. User knows the servant (in which case it is needed to know the serviced classes) and sends messages with requests to the servant instances, passing the serviced objects as parameters. The serviced classes (geometric objects from our example) don’t know about servant, but they implement the “IServiced” interface. The user class just calls the method of servant and passes serviced objects as parameters. This situation is shown on figure 1.
  2. Serviced instances know the servant and the user sends them messages with requests (in which case it isn't necessary to know the servant). The serviced instances then send messages to the instances of servant, asking for service. On figure 2 is shown opposite situation, where user don’t know about servant class and calls directly serviced classes. Serviced classes then asks servant themselves to achieve desired functionality.

Example

[edit]

This simple Java example shows the situation described above. This example is only illustrative and will not offer any actual drawing of geometric objects, nor specification of what they look like.

// Servant class, offering its functionality to classes implementing
// Movable Interface
public class MoveServant {
	// Method, which will move Movable implementing class to position where
	public void moveTo(Movable serviced, Position where) {
		// Do some other stuff to ensure it moves smoothly and nicely, this is
		// the place to offer the functionality
		serviced.setPosition(where);
	}

	// Method, which will move Movable implementing class by dx and dy
	public void moveBy(Movable serviced, int dx, int dy) {
		// this is the place to offer the functionality
		dx += serviced.getPosition().xPosition;
		dy += serviced.getPosition().yPosition;
		serviced.setPosition(new Position(dx, dy));
	}
}

// Interface specifying what serviced classes needs to implement, to be
// serviced by servant.
public interface Movable {
	public void setPosition(Position p);

	public Position getPosition();
}

// One of geometric classes
public class Triangle implements Movable {
	// Position of the geometric object on some canvas
	private Position p;

        // Method, which sets position of geometric object
	public void setPosition(Position p) {
		this.p = p;
	}

	// Method, which returns position of geometric object
	public Position getPosition() {
		return this.p;
	}
}

// One of geometric classes
public class Ellipse implements Movable {
	// Position of the geometric object on some canvas
	private Position p;

	// Method, which sets position of geometric object
	public void setPosition(Position p) {
		this.p = p;
	}

	// Method, which returns position of geometric object
	public Position getPosition() {
		return this.p;
	}
}

// One of geometric classes
public class Rectangle implements Movable {
	// Position of the geometric object on some canvas
	private Position p;

	// Method, which sets position of geometric object
	public void setPosition(Position p) {
		this.p = p;
	}

	// Method, which returns position of geometric object
	public Position getPosition() {
		return this.p;
	}
}

// Just a very simple container class for position.
public class Position {
	public int xPosition;
	public int yPosition;

	public Position(int dx, int dy) {
		xPosition = dx;
		yPosition = dy;
	}
}

Similar design pattern: Command

[edit]

Design patterns Command and Servant are very similar and implementations of them are often virtually the same. The difference between them is the approach to the problem.

  • For the Servant pattern we have some objects to which we want to offer some functionality. We create a class whose instances offer that functionality and which defines an interface that serviced objects must implement. Serviced instances are then passed as parameters to the servant.
  • For the Command pattern we have some objects that we want to modify with some functionality. So, we define an interface which commands which desired functionality must be implemented. Instances of those commands are then passed to original objects as parameters of their methods.

Even though design patterns Command and Servant are similar it doesn’t mean it’s always like that. There are a number of situations where use of design pattern Command doesn’t relate to the design pattern Servant. In these situations we usually need to pass to called methods just a reference to another method, which it will need in accomplishing its goal. Since we can’t pass references to methods in many languages, we have to pass an object implementing an interface which declares the signature of passed method.

See also

[edit]

References

[edit]

Resources

[edit]

Pecinovsky, Rudolf; Jarmila Pavlí?ková; Lubo? Pavlí?ek (June 2006). Let's Modify the Objects First Approach into Design Patterns First (PDF). Eleventh Annual Conference on Innovation and Technology in Computer Science Education, University of Bologna.

惨绿少年什么意思 土豆炒什么好吃 三什么什么什么成语 头皮屑多是什么原因 孕妇做春梦是什么意思
鱼腥草长什么样 吃头孢为什么不能喝酒 开黄腔什么意思 川字加一横是什么字 为什么开空调没蚊子
什么是气滞 手淫过度有什么危害 tid是什么意思 七月份出生是什么星座 最小的一位数是什么
slogan是什么意思啊 24k镀金是什么意思 结痂什么意思 肺结核是什么病 四川古代叫什么
一味是什么意思hcv8jop2ns8r.cn 甲状腺球蛋白抗体高是什么原因hcv9jop2ns6r.cn boys是什么意思hcv9jop1ns5r.cn 下身有点刺痛什么原因hcv7jop9ns5r.cn 10月13号是什么星座hcv7jop5ns6r.cn
一千年前是什么朝代hcv8jop3ns8r.cn 指南针是什么时候发明的hcv9jop7ns1r.cn 渣滓是什么意思dayuxmw.com 抽脂手术对身体有什么副作用hcv8jop3ns0r.cn 孕吐什么时候结束hcv8jop2ns3r.cn
歧视是什么意思hcv8jop9ns1r.cn 用淘米水洗脸有什么好处hcv8jop5ns1r.cn 三七有什么功效和作用hcv7jop9ns0r.cn 光杆司令是什么意思hcv9jop3ns3r.cn 乘胜追击什么意思hcv7jop6ns8r.cn
过期不候是什么意思hcv9jop7ns9r.cn 小儿惊风是什么症状hcv9jop1ns9r.cn gold什么意思bysq.com 锦纶是什么面料优缺点wuhaiwuya.com 三月初九是什么星座96micro.com
百度