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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:35:45+00:00 2026-05-13T01:35:45+00:00

Take this skeleton class that someone wants to fill in to fetch RSS streams

  • 0

Take this skeleton class that someone wants to fill in to fetch RSS streams on a series of web sites:

public class RSSStream extends Thread {

    public RSSStream(String rssStreamName,String rssURL,int refreshTime){
        // constructor code goes here
    }
}

Now, let’s consider that refreshTime has to be higher than zero and that rssURL should be a valid http address.

The obvious reflex is to have some value checking logic inside the constructor. However, a call to the constructor instantiates an Object whatever happens. This means the Object ends up being useless if the values don’t allow it to do it’s job. This also means that the Object should be eventually dumped or reused.

So, here’s a couple of questions on the subject:

  • Why do some classes impose a getInstance() method coupled with what is probably a private constructor ? If I remember well, one example would be GregorianCalendar.
  • In what cases would you use this same approach ?
  • In most cases do you have the checking logic in your constructor ?
  • If so, do you apply this or not to Entity-style classes used in the persistence context of a domain model ?

All your answers are welcome. It’ll be interesting to get a clear view of the most common practise is.

  • 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-13T01:35:45+00:00Added an answer on May 13, 2026 at 1:35 am

    A few of the most common things:

    • If you use FactoryMethod for the construction of complex objects you’ll typically have a private constructor and require instantiation through the factory. This supports switching construction strategies with the factory.

    • Clearest to me would be throw a custom ( and hopefully informative ) Exception in the constructor if instantiation can’t happen: :

      public class Person {

          public Person(Integer id, String name) throws InvalidPersonException
               if (name==null) throw new InvalidPersonException("You cant have a person without a name");
               ...
      
    • This is likely to create a mess in entity persistence objects, mostly because you want these objects to be logic-free, and because the framework should handle this for you – e.g. if you have a bean containing (id, name) in hibernate and try to persist into a table with the name required to be non-null, the error the db throws or from your configuration should be sufficient.

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

Sidebar

Related Questions

Take this sample class as an example: [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class BugFixAttribute : System.Attribute
Take this class as example: public class Category : PersistentObject<int> { public virtual string
take this simple code: class A{ public: virtual void foo() = 0; void x(){
Take this class for example: public class Applicant : UniClass<Applicant> { [Key] public int
Take this code: public class MyClass { private final Object _lock = new Object();
Take this class: package { import flash.display.MovieClip; public class test extends MovieClip { public
Take this example: public class foo { public int[] func() { int arr[] =
Take this POJO as the domain. public class Invoice { private String codeNumber; private
Take this class for an example: <?php class Person { private $name = null;
take this example from google docs class BrowseHandler(webapp.RequestHandler): > def get(self, category, product_id): >

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.