w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
One class makes instances of another class. These instances need to use information in original class, how to organize?

seems pretty much ok to me, I'd just hide the event_list implementation in the Simulation class:

public class Simulation
{
    private LinkedList<Event> event_list = new
LinkedList<Event>();

    public void addEven(Event x) {event_list.Add(x); }
}

passing this in constructor is ok, if you really want to you can put a factory method in simulation:

public class Simulation
{
    public Machine CreateNewMachine() { return new Machine(this); }
}

to just allow Machine m1 = Simulation.CreateNewMachine()





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.