user5161995
user5161995

Reputation:

What is the type of Java class that exposes public variables?

There's a term that's used to describe a type of class that exposes its member variables as public. Does someone know what I'm talking about? I think the term hinted at not a kind of design pattern, but it did describe why the class is used that way.

If you would like an example...

public class HoldsLotsOfStuff {
   public String forgetMeNot;
   public String anotherThingToRemember;
   public int size;
   // etc.
}

And then instead of using accessor methods, you would just do this (I understand it's not recommended, btw):

stuffHolder = new HoldsLotsOfStuff();
stuffHolder.size = 10;
stuffHolder.forgetMeNot = "flowering plants lalala";

Thanks.

Upvotes: 0

Views: 71

Answers (1)

scottb
scottb

Reputation: 10084

Josh Bloch referred to classes which:

  • may or may not have an explicit constructor
  • expose instance fields
  • are used for packaging convenience, usually with package-private accessibility (or narrower)

as degenerate classes in Effective Java, 2nd Ed.

Upvotes: 1

Related Questions