Pitfalls of composition where component is also a component of a sibling component?

I’m relatively new to structuring code in a composition style, and I have a situation where a component is also a component of a sibling component. I’m trying to figure out if there are likely to be unexpected issues with this.

Explaining the relation in more detail, I have a composite C that has components A and B. However, A is also a component of B. That is, B is also a composite, and also uses A as a component, even though B is also a component of C. Notably, B may potentially be replaced by a version of that does not always require A or will have two separate instances of A, so I don’t want C to use B‘s A, and it should have it’s own reference to A. But most often, C and B will need to refer to the same A.

As the concrete case, I’m building a machine learning framework for others to use. I’m attempting to build file-based dataset classes. There will be both a training and an infer dataset class. They both need access to a component that will take care of managing paths to the data files. The infer dataset needs to also have the ability to load the input data from the file paths. The training dataset will have the infer dataset as a component (so it can load the input data in the same way). The training dataset also needs to know how to load the labels from the file paths (not all infer datasets will have labels, which is why this is separate). So, most often, the training and infer dataset will need to share the same path management component. However, there are cases when the two datasets may have separate path management components, or one might be an alternative version of the class that does not have a path management (synthetic data generated on-the-fly, label and input data residing in different files, etc).

2

C uses A and B
B uses A

This is not that strange. Or really that important. What is important is understanding what B and C need from A.

It’s worth thinking about the dry principle for a moment. It teaches us not to worry about duplicated code as much as duplicated ideas.

B and C each have needs. For the moment, A meets those needs. But B and C are different things. It’s worth considering I, the interface between them and A.

The job of I shouldn’t be to allow everything A can do. It should be to express what B and C need. But only if they need exactly the same things. If they need different things, they need to express them through different interfaces. Even if those interfaces hold exactly the same code. Dry up ideas. Not code.

Give the users that kind of respect and this dependency knot should be easier to manage.

3

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