有时,它需要支持国家对物体的支持。
- ENUM (SIMPLE)
- STATE pattern (OC principle)
显然,需要为此目的使用国家模式(我不确定)。
But reading other code I often face with enum only not state pattern at all. Does state pattern has power?
有时,它需要支持国家对物体的支持。
显然,需要为此目的使用国家模式(我不确定)。
But reading other code I often face with enum only not state pattern at all. Does state pattern has power?
为什么我们使用国家模式? 消除有条件的逻辑重复,用多种形态取代有条件的代码。
什么时候我们有有条件的逻辑重复? 当我们有许多取决于国家的行动时,你必须在每一个行动中重复你的有条件的逻辑。当你有很多国家的时候,它就会变得非常令人烦恼。 代码重复意味着当你加入新的国家时,你应该更新每一个重复的代码。
因此,如果我没有重复有条件逻辑,我宁可采用基于enum的状态,而不要为各州建立新的等级等级体系,为各州创造许多等级。 有时我甚至更喜欢有条件逻辑重复:比如,当我有许多州,但只有极少数国家独立行动。 在这种情况下,我宁愿有两个切换区块,而不是创建十个新等级。
一般来说, EENUM 方法涉及某种状态和转变的表格(数组)。而设计模式在对象上也实现了相同的效果。
如果您没有提及与ENUMs的表格方法,那么如果块块(如果块块)非常难以管理,那么解决方案就需要涉及一个大的如果/ele(如果块),而块块则相当难以管理。 关于下面的一节,我想很明显的是,这个特定的解决方案是低级的。
以下是我所列举的,作为每个项目的方案和国家委员会。
<强 > ENUM表 强 >
方案:
国家理事会:
<强 > 设计模式 强 >
方案:
国家理事会:
Since web applications are mostly stateless, and linear (request comes in, response goes out), is change-tracking really necessary? E.g. if I have an action that updates a Product instance I know at ...
Ok, the context is some serialization / deserialization code that will parse a byte stream into an object representation that s easier to work with (and vice-versa). Here s a simplified example ...
While designing ORM, what is the best approach to represent the relationship, performance-wise? I mean, out of the following two, which approach is best considering performance? class Employee { ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
Is there a design pattern for managing a queue or a stack? For example, we are looking to manage a list of tasks. These tasks will be added to a group queue, users will then be able to pull off the ...
I have started upgrading one of our internal software applications, written in ASP.NET Web Forms, and moving to ASP.NET MVC. I am trying to leverage the Repository design pattern for my classes, ...
I have a Car object which contains a latitude field and a longitude field. I use the observer pattern so that any time either of these fields change in my application, my car object is notified. I ...
How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...