Is this a named pattern?

2019-07-31 05:01发布

问题:

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

Greetings,

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 ?

回答1:

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

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



回答2:

This could be referred as Wrapper pattern.