Software pattern for combining properties [closed]

I have two classes that read distinct files. As an examples, two classes, sourceA or Client, and sourceB or Resources:

public class Client()
{
    public string ClientName {get; set;}
    public int ClientNumber {get; set;}
    public string Address {get; set;}
    //...
}

public class Resources()
{
    public int ClientNumber {get; set;}
    public decimal Resources {get; set;}
    //...
}

Let’s say that I need to merge booth classes into a new one, but I just need some fields from class Client and Resources. Is there any software pattern motivated by something like this, to compose a class like ClientReport?

The new class should be something like this:

public class ClientReport()
{
    public string ClientName {get; set;}
    public int ClientNumber {get; set;}
    public string Address {get; set;}
    public decimal Resources {get; set;}

    public int CalculateRating()
    {
        //...
    }
}

These new classe will have some properties of Client and Resources, and copying code from them in order to create ClientReport seems to be a repetition, and I think it should be a away to compose this class and only use the needed properties from Client and Resources.

8

Here are (at least) two objects client and report involved.
From what you write so far, a report seems best to be composed of a client and ressources:

public class ClientReport()
{
    public Client client;
    public decimal ressources;

    public getClientName(){ return this.client.getName(); }
    // ...
    public setRessources(decimal ressources){ this.ressources=ressources; }

    public ClientReport(Client client){
        this.client=client;
    }
}

Instead of copying the fields of the Client you should wrap the Client into the ClientReport (pass it via constructor) and delegate incoming calls of the report to the Client itself (see getClientName()). So you are free to hide/show (= encapsulate), whatever part of the Client you want. It makes sense to hide the creation of the ClientReport behind a Builder. The Builder reads first SourceA to generate the List<Clients>. After that it reads SourceB to map the ressources to the respective client. The Builder itself has only one method getClientReports(), which does all that transparently to the consumer.

You should further clean up your object design. Perhaps it makes sense in your domain to have an Address-object, which is wrapped by the Client object.

2

The definition of your client class should not be tied to how you acquire the data to construct the class. You should review your business requirements of your client class and define it based on that only.

From what you have shown so far, it looks like you need two file processing classes which both are provided a collection of client objects to work on, whether that is for creation or update.

The key thing is that the client class needs to be freestanding from the processing needed for the files. Tomorrow you may need to read from a database, or a web service, or something else, but that certainly doesn’t change the definition of a client in your business domain.

4

If I understand your question, the Facade Pattern fits your needs:

Intent:

  • Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem
    easier to use.
  • Wrap a complicated subsystem with a simpler interface.

Your Facade, the ClientReport class, has classes SourceA and SourceB by composition. The simpler, unified interface provided by ClientReport delegates to the appropriate methods of SourceA and SourceB; however, the client deals only with the ClientReport interface.

The link above has this checklist for using the Facade pattern:

  1. Identify a simpler, unified interface for the subsystem or
    component.
  2. Design a ‘wrapper’ class that encapsulates the subsystem.
  3. The facade/wrapper captures the complexity and collaborations of the
    component, and delegates to the appropriate methods.
  4. The client uses (is coupled to) the Facade only.
  5. Consider whether additional Facades would add value.

1

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