这是命名模式吗? [英] Is this a named pattern?

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

问题描述

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
    // ...
}

您好,

我有两个提供相同属性的类.第一个允许读取和写入他的所有属性,第二个只允许读取.我发现这样做更容易创建值对象,而不是一个巨大的构造函数(以后可能会有所不同).构建器模式涉及一个专门用于创建对象的类,在我看来,对于一个简单的值对象来说太多了".

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 ?

推荐答案

如果我正确理解了您想要识别的代码的哪一部分,那么是的,它确实有一个通用名称.

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天全站免登陆