What naming convention should you use for data objects solely meant for parameters [closed]

This is my pseudocode for DAL:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>CusOrderDTO GetCustomerOrder(DateTime OrderDate, string customerCode)
CusOrderDTO orderSet = new CusOrderDTO()
* query data from database, populate CusOrderDTO
return orderSet
</code>
<code>CusOrderDTO GetCustomerOrder(DateTime OrderDate, string customerCode) CusOrderDTO orderSet = new CusOrderDTO() * query data from database, populate CusOrderDTO return orderSet </code>
CusOrderDTO GetCustomerOrder(DateTime OrderDate, string customerCode) 
    CusOrderDTO orderSet = new CusOrderDTO()
    * query data from database, populate CusOrderDTO
    return orderSet

Now the parameters for the DAL have grown so large that I should pass a custom data object for parameter

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>CusOrderDTO GetCustomerOrder(SomeParameterClassName orderParameters)
</code>
<code>CusOrderDTO GetCustomerOrder(SomeParameterClassName orderParameters) </code>
CusOrderDTO GetCustomerOrder(SomeParameterClassName orderParameters)

What naming convention is generally used for SomeParameterClassName? Naming it DTO seems weird since it’s solely used for parameter purposes only and service layer is only going to work on CusOrderDTO object.

For the above, please assume that CusOrderDTO and orderParameters have nothing in common.

  • If SomeParameterClassName regroups logically connected objects, then name it accordingly.

    For instance, if it regroups coordinate X, Y and Z, name it 3DPoint. If it regroups the product name, product price and product description, name it Product.

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>void Demo(int x, int y, int z) { }
    ――― ↧ ―――
    void Demo(3DPoint coordinates) { }
    </code>
    <code>void Demo(int x, int y, int z) { } ――― ↧ ――― void Demo(3DPoint coordinates) { } </code>
    void Demo(int x, int y, int z) { }
                ――― ↧ ―――
    void Demo(3DPoint coordinates) { }
    

    and:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>void Demo(string productName, int productPrice, string productDescription) { }
    ――― ↧ ―――
    void Demo(ProductInfo product) { }
    </code>
    <code>void Demo(string productName, int productPrice, string productDescription) { } ――― ↧ ――― void Demo(ProductInfo product) { } </code>
    void Demo(string productName, int productPrice, string productDescription) { }
                ――― ↧ ―――
    void Demo(ProductInfo product) { }
    
  • If SomeParameterClassName regroups objects which have nothing in common except being passed to the same method, then you are doing it wrong. There is no need to create a type for unrelated entities: just pass them as-is to the method.

    For instance, if it regroups coordinate X and product description, remove the object and pass two parameters.

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>void Demo(int x, string productDescription) { }
    ――― ↺ ―――
    </code>
    <code>void Demo(int x, string productDescription) { } ――― ↺ ――― </code>
    void Demo(int x, string productDescription) { }
                ――― ↺ ―――
    
  • It may be that you have many parameters passed to a method, but not all can be grouped. In this case, search for the ones you can group, and leave the others.

    For instance, with parameters such as product name, product price, product description and logger, then group first three into a product class and leave the last one:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>void Demo(string productName, int productPrice,
    string productDescription, AppLogger logger) { }
    ――― ↧ ―――
    void Demo(ProductInfo product, AppLogger logger) { }
    </code>
    <code>void Demo(string productName, int productPrice, string productDescription, AppLogger logger) { } ――― ↧ ――― void Demo(ProductInfo product, AppLogger logger) { } </code>
    void Demo(string productName, int productPrice,
              string productDescription, AppLogger logger) { }
                ――― ↧ ―――
    void Demo(ProductInfo product, AppLogger logger) { }
    

In a presence of a method which accepts many disparate parameters, additional refactoring may be required. For example, in the previous piece of code, one may wonder why is AppLogger passed as a parameter, instead of being injected when calling a constructor:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>var something = new Something();
...
something.Demo(product, logger);
――― ↧ ―――
var something = new Something(logger);
...
something.Demo(product);
</code>
<code>var something = new Something(); ... something.Demo(product, logger); ――― ↧ ――― var something = new Something(logger); ... something.Demo(product); </code>
var something = new Something();
...
something.Demo(product, logger);
          ――― ↧ ―――
var something = new Something(logger);
...
something.Demo(product);

Since other method of Something are probably logging their activity as well, injecting the logger in the constructor makes sense.

Another refactoring technique is to split the method. The large number of parameters is a good indication that the method does too much. There are sometimes obvious cases:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>void Demo(a, b, c, d, e, f, g, h)
{
if (a)
{
// A few hundred lines which use exclusively the parameters b, c and d.
}
else
{
// A few hundred lines which use exclusively the parameters e, f, g and h.
}
}
</code>
<code>void Demo(a, b, c, d, e, f, g, h) { if (a) { // A few hundred lines which use exclusively the parameters b, c and d. } else { // A few hundred lines which use exclusively the parameters e, f, g and h. } } </code>
void Demo(a, b, c, d, e, f, g, h)
{
    if (a)
    {
        // A few hundred lines which use exclusively the parameters b, c and d.
    }
    else
    {
        // A few hundred lines which use exclusively the parameters e, f, g and h.
    }
}

but most are less obvious: some parameters may be used through the entire method, may be interconnected, etc. Still, if you feel like you have too many parameters, look at other indications (such as LOC, ILLOC in C# and the number of branches) and check if your method is doing one and one only thing.

I agree with MainMa: group locally connected objects. In case there is no other connection, there is still the request / query:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>CusOrderDTO GetCustomerOrder(CustomerOrderQuery query)
</code>
<code>CusOrderDTO GetCustomerOrder(CustomerOrderQuery query) </code>
CusOrderDTO GetCustomerOrder(CustomerOrderQuery query)

I add Request or Query to parameter objects.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật