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 7560749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:59:00+00:00 2026-05-30T12:59:00+00:00

Kindly don’t mind my question as it is a little theoretical. Last week I

  • 0

enter image description hereKindly don’t mind my question as it is a little theoretical.

Last week I gave an interview for job where I was given an assignment to and later they ask question and my design was faulty. So I couldn’t get the job. I am sharing my design. Please see it and suggest me where I am wrong and what solution will be a good design of it.

Problem
This is a package for a construction company who builds swimming pools. Swimming pool has 2 parts swimming pool surrounding area and pool it self. Both (pool and surrounding area) can be in rectangular or circular shape (please see attached picture) and so there will be 4 possible shapes. Program should calculate shaded area (outer area of pool to concrete).

****Formula** to calculate rectangular area** is Length * Width * 2
Formula to calculate circular area is 2 * 2.1718

My Design
I made IPool Interface with 2 methods (1) CalculateCircularArea (2) CalculateRectangularArea. Made 2 classes (CircularPool, RectangularPool) implementing IPool interface.

Question
What if there are more shapes other then rectangular and circular. Say if there are 100 other shapes, what solution will be considering future prospectus ? Here my design was not good as it was requiring change in interface when ever a new shape comes.

  • 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-30T12:59:01+00:00Added an answer on May 30, 2026 at 12:59 pm

    The design was already given in the question: A swimming pool has-a surrounding and it has-a inner pool. The task calls for composition rather then inheritance.

    With that design we can invent other pool shapes and surroundings and still have swimming pools

    public interface SwimmingPool {
      Surrounding getSurrounding();
      Pool getPool();
      double getOuterArea();
    }
    
    public interface Surrounding extends Shape{
      // some methods for surroundings
    }
    
    public interface Pool extends Shape {
      // some methods for pools
    }
    
    public interface Shape {
       double getArea();
    }
    

    Next you create concrete classes for rectangular and circular pools and surroundings use those modules to design swimming pools.


    Now, we create a concrete swimming pool class:

    public SwimmingPoolImpl implements SwimmingPool {
     private Surrounding surrounding;
     private Pool pool;
     public SwimmingPoolImpl(Surrounding surrounding, Pool pool) {
       this.surrounding = surrounding;
       this.pool = pool;
     }
    
     public double getOuterArea() {
       return surrounding.getArea() - pool.getArea();
     }
    
     public Surrounding getSurrounding() { return surrounding; }
     public Pool getPool() { return pool; }
    }
    

    Imagine, we have a library of dozens of differen pools and surroundings and we want to create a custom swimmingpool:

    SwimmingPool customPool = new SwimmingPoolImpl(new OvalSurrounding(), new StarShapedPool());
    double pavementArea =  customPool.getOuterArea();
    

    That’s it. Now we can mainatin a library of different pools and outer areas and use them immediatly to create swimming pools without having to change the swimming pool implementation. That’s the benefit of composition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new in JavaScript & jQuery so, kindly don't mind my very basic
Totally new to programming so kindly excuse the silly question. I have this URL
I don't have much knowledge in TRIGGERS, below is my doubt kindly suggest any
I have been told, AppKit controls don't take kindly to being updated from threads
I don't know if anyone could kindly explain this code for me? unsigned int
As a novice, I really don't know much about javascript. Kindly help me in
I was kindly helped by Jonathan over here simple javascript question-linking button state to
Since I don't have a machine to test this I kindly need your help
Kindly go through this link and notice the solution given by "thepeer": https://stackoverflow.com/a/3494108 I
Ok, I'm sorry if this is a little bit confusing but I don't know

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.