简体   繁体   English

C#对象层次结构设计

[英]C# Object Hierachy Design

I have created a series of related objects in my C# application... 我在C#应用程序中创建了一系列相关对象...

Object A contains a list made up of Object B's, Object B's contain a list of Object C's. 对象A包含由对象B组成的列表,对象B包含对象C的列表。

Object A is currently writing information to a log file, depending on Object A's instance name (eg there are three Object A instances in my application "Server 1", "Server 2", "Server 3"). 对象A当前正在根据对象A的实例名称将信息写入日志文件(例如,在我的应用程序“服务器1”,“服务器2”,“服务器3”中有三个对象A实例)。 So each instance of Object A writes to it's own log file. 因此,对象A的每个实例都会写入其自己的日志文件。

How do I get Object B to write information to the "Server 1" log file if it is in a collection belonging to "Server 1"? 如果对象B属于“服务器1”的集合中,如何获取对象B来将信息写入“服务器1”日志文件?

As far as I know, Object B does not know it is part of a collection of Object B's belonging to Object A. Object B knows nothing about Object A and hence can't get Object A's name to write to the same log file for the particular instance of Object B. 据我所知,对象B不知道它是对象B属于对象A的集合的一部分。对象B对对象A一无所知,因此无法获取对象A的名称写入该对象的同一日志文件中。对象B的特定实例。

Have I designed this poorly? 我设计不好吗? Is there a method or way for Object B to check if it is part of some collection at runtime and get information from Object A? 是否有方法或方法让对象B在运行时检查它是否是某个集合的一部分并从对象A获取信息?

最后,按照建议,我可以将父母的名字传递给孩子,并在登录时使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM