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

  • Home
  • SEARCH
  • 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 802443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:36:11+00:00 2026-05-14T23:36:11+00:00

I am supposed to make a class that should be a container for an

  • 0

I am supposed to make a class that should be a container for an interval of values (like in mathematics). I have already decided that I’ll use internally a SortedSet.

One of the the things I’m supposed to implement is a method that “gets an ordered set with all the elements in the interval”.

class Interval {
    private SortedSet sortedSet = new something();

    ...

    <<method that should return an ordered set of values>>
}

My question resides in what should be both the method’s return type and name. Several hypothesis arise:

  1. SortedSet getSortedElements(); I am internally using a SortedSet, so I should return that type. I should state that intent in the method’s name.
  2. SortedSet getElements(); I am internally using a SortedSet, but there’s no point in stating that in the method name(I don’t see a big point in this one).
  3. Set getElements(); I should try to always return the most basic type, thus I am returning a Set. By the contract and definition of the method, people already know all the elements are in order.
  4. Set getSortedElements(); For the method return type, the same as above. About the method name, you are stating clearly what this method is going to return: a set of elements that are sorted.

I’m inclined to use 4. , but the others also seem alright. Is there a clear winner? Why?

  • 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-14T23:36:12+00:00Added an answer on May 14, 2026 at 11:36 pm

    SortedSet is an interface with the contract that the elements are sorted. It also exposes some methods not available in Set (such as first()). If you are supposed to return an object that obeys that contract (for example, returns ordered values on iterator()), then you should return a Sorted Set. If not, you should return a Set (or a Collection).

    You figure out what to return based on how you want the result to be used. Think what “gets an ordered set with all the elements in the interval” means first, then worry about the implementation.

    By the way the code

    private SortedSet sortedSet = new SortedSet();
    

    is illegal, because SortedSet is an interface. Since this is homework I will leave it to you to figure out why that is a problem.

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

Sidebar

Related Questions

I have a class that contains a member object. I would like to call
It seems to me that introducing an ORM tool is supposed to make your
Are we supposed to find workarounds in our web applications so that they will
How am I supposed to use merge with the latest version of Tortoise SVN?
For my semester project, my team and I are supposed to make a .jar
The problem: I have a class which contains a template method execute which calls
I'm trying to make a web scraper that will parse a web-page of publications
Suppose you want to make an async request in JavaScript, but you want to
Can you make file copying faster through multiple threading? Edit : To clarify, suppose
I'm supposed to create a simple rule engine in C#. Any leads on how

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.