简体   繁体   中英

How to add a property that will be passed through more than one class

I am currently creating a programme that will be based on a virtual cell simulation. For this I have seperate classes called machine, worksettingstation, robot and component. I need to be able to pass a component through each class depending on where it is in the cell. How would I create a property to do this? Also when it leaves the specific class it will return null as the component has moved. This will eventually move to a WPF but at the moment I'm just trying to show it in a simple class.

Is there a way I can simply just add a new property to each class and then reference it to the class called component and do a simple check to see if it has been passed on yet?

Implementing an Interface in the concrete classes and combining that with Dependency Injection should be the best way to achieve this.

Dependency Injection : Why does one use dependency injection?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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