I'm including an encapsulation hierarchy table of several of the GoF
design patterns to help explain the differences between these two
patterns. Hopefully it better illustrates what each encapsulates so my
explanation makes more sense.
First off, the hierarchy lists the scope for which a given pattern is
applicable, or the appropriate pattern to use to encapsulate some level
of detail, depending on which side of the table you start at.
As you can see from the table, a Strategy Pattern object hides
details of an algorithm's implementation, so the use of a different
strategy object will perform the same functionality but in a different
way. Each strategy object might be optimized for a particular factor or
operate on some other parameter; and, through the use of a common
interface, the context can safely work with either.
The Command Pattern encapsulates a much smaller level of detail than
an algorithm. It encodes the details needed to send a message to an
object: receiver, selector and arguments. The benefit to objectifying
such a tiny part of the process execution is that such messages can be
invoked along different points of time or location in a general way
without having to hard-code its details. It allows messages to be
invoked one or more times, or passed along to different parts of the
system or multiple systems without requiring the details of a specific
invocation to be known before execution.
As is typical for design patterns, they do not require all
implementations to be identical in detail to bear the pattern name.
Details can vary in implementation and in what data is encoded in the
object versus as method arguments.
分享到:
相关推荐
在策略模式(Strategy Pattern)中,一个类的行为或其算法可以在运行时更改。这种类型的设计模式属于行为型模式。 在策略模式中,我们创建表示各种策略的对象和一个行为随着策略对象改变而改变的 context 对象。...
前端大厂最新面试题-Strategy Pattern
strategy-pattern-in-unity
定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。本模式使得算法的变化可独立于使用它的客户。
head-first-design-pattern源码,第一章strategy-pattern(策略模式),融入了自己的见解,有一些错误的实现,也有一些标准答案,对照着看更能理解模式的精髓。
Head.First设计模式中的The Factory Pattern(工厂模式)ppt
设计模式——策略模式Strategy design pattern _ model
NULL 博文链接:https://bossshit.iteye.com/blog/715672
Strategy pattern implemented
策略模式demo-处理不同订单类型的订单-->策略模式的核心是要把频繁发生变化的部分封装起来,作用是把变化部分的影响隔离开,避免局部的变化对其它fixed部分造成影响,设计时可能需要更多的时间,但便于维护、复用与...
(原文:The Strategy Pattern defines a family of algorithms,encapsulates each one,and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.)
主要介绍了C#策略模式(Strategy Pattern),以一个简单的实例讲述了C#策略模式的实现方法,包括策略模式的用途以及具体实现方法,需要的朋友可以参考下
headfirst design pattern C++ code(first chapter strategy's code for linux)
基于springboot做了一个策略模式的demo(开箱即用)
Creating your strategy: Define the components of your technology strategy using proven patterns Communicating the strategy: Convey your technology strategy in a compelling way to a variety of ...
策略模式StrategyPattern,通过实现鸭子的飞行策略以及叫声策略演示策略模式的具体实现!
介绍 Design Pattern的用处,定义,分类,并对几个典型性Design Pattern进行举例说明,如strategy Design Pattern
Strategy_Pattern
NULL 博文链接:https://lym6520.iteye.com/blog/690554
备忘录模式(Memento Pattern) 策略模式(Strategy Pattern) 抽象工厂模式(Abstract Factory Pattern) 代理模式(Proxy Pattern) 单例模式(Singleton Pattern) 迭代器模式(Iterator Pattern) 访问者模式(Visitor ...