Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6787797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:24:32+00:00 2026-05-26T17:24:32+00:00

My problem is the following, I have a class, let’s call it Theatre .

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:24:33+00:00Added an answer on May 26, 2026 at 5:24 pm

    This is how you solve it. Pass the Theatre as an argument to Show

     class Theatre
        {
            public Theatre(int numberOfSeats)
            {
                NumberOfSeats = numberOfSeats;
            }
            public int NumberOfSeats { get; private set; }
        }
    
        class Show
        {
            List<Seats> listOfSeats = new List<Seats>();
    
            public Show(Theatre theatre)
            {
                for (int i = 0; i < theatre.NumberOfSeats; i++) //  <---- And here is my problem!!
                {
                    //Code to add to list
                }
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Theatre myTheatre = new Theatre(100);
                Show myShow = new Show(myTheatre);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I ran into the following problem with NUnit. I have a class, that
I have the following problem in Struts 2. Let's assume i have a class
Let's say I have the following class structure (simplified from my real-world problem): Public
I have a class, let's call it Foo , which contains the 3 following
I have the following problem: let's say class Item holds the serial number of
I have the following problem: I have the class: class Word(object): def __init__(self): self.id
I have the following problem. I have a class named A in which I
I have the following problem with inheritance and templates: class Base {}; class Deriv
Good day, I have the following problem: class B extends class A and methods
I have the following tricky problem: I have implemented a (rather complicated) class which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.