My problem is the following, I have a class, let’s call it Theatre.
This Theatre has a constructor where I specify the amount Seats that this Theatre has.
The Show class, has an collection of Seats, each with its own properties like bool Empty.
So summing up the code:
class Theatre
{
public Theatre(int numberOfSeats)
{
this.numberOfSeats = numberOfSeats;
}
}
Lets say we instantiate it somewhere to 100.
Theatre myTheatre = new Theatre(100);
For the Show class:
class Show
{
List<Seats> listOfSeats = new List<Seats>();
public Show()
{
for (int i = 0; i < 100; i++) // <---- And here is my problem!!
{
//Code to add to list
}
}
}
My problem is I don’t know to get rid of that 100.
I would like to have something like myTheatre.NumberOfSeats, but I’m not really sure how would that work.
My problem is, I have already instantiated myTheatre in another class, so I would have to make a new theatre inside Show, only to get the number of seats, I would use something like composition and deletagation, but that would clearly violate ISP.
But even that has a problem, since, when I make the new Theatre, I would have to put 100 as a paratmer and, if that were to change, I would have to manually change it.
So my questions are:
- Am I missing something obvious? (Very likely)
- What approach would you recommend?
- Is there something like a shared variable across classes? (Don’t want to use the word global, because I’m not sure that’s what I want, but it might).
As an obvious clarification, the above is not the actual code, just a representation to clarify the situation.
This is how you solve it. Pass the Theatre as an argument to Show