这是一个名为格局? [英] Is this a named pattern?

查看:117
本文介绍了这是一个名为格局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class BanknoteDescriptor
{
    public double Value { get; set; }
    public string Currency { get; set; }
}

public class Banknote
{
    private BanknoteDescriptor _description;

    public Banknote(BanknoteDescriptor description)
    {
        _description = description;
    }

    public double Value
    {
        get { return _description.Value; }
    }
    public string Currency
    {
        get { return _description.Currency; }
    }

    // Overring in order to create a value object
    // ...
}

问候,

我有两个类,它们提供相同的属性。第一个允许读取和对他的所有财产写作,第二个只允许读。我觉得它更容易这样做创建的,而不是一个巨大的构造函数(即可以在以后发生变化)值对象。 Builder模式涉及到一个专门创建一个对象类,并似乎在我的眼前太多,一个简单的值对象。

I have two classes that provide the same properties. The first one allows reading and writing on all of his properties, the second one only allows reading. I find it easier to create value objects by doing so, instead of a huge constructor (that could vary later). Builder pattern involves a class dedicated in creating an object, and seems "too much" in my eyes, for a simple value object.

所以,问题是,这是一个名为格局?是不是有人之前就已经使用这种伎俩?我会通过与回事遇到问题以后呢?

So, the questions are, is this a named pattern ? Did someone already use this kind of trick before ? Would I meet problems later by going on with that ?

推荐答案

如果我理解正确你想确定然后是,它确实有一个共同的名字。您的code的它的确切一部分

If I correctly understood which exact part of your code you want identified then yes, it does have a common name.

引入一种封装的参数列表,以便代替的正如你所说,你只有一个参数对象称为引入参数对象巨大的构造并为一类在重构模式Fowler的目录中列出。

Introducing a class that encapsulates a list of parameters so that instead of a huge constructor as you have said you have just one parameter object is called Introduce Parameter Object and is listed in Fowler's catalog of refactoring patterns.

http://www.refactoring.com/catalog/introduceParameterObject.html

这篇关于这是一个名为格局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆