java - Does a class without fields have a special name? -


what class without fields called? i'm beginner in programming java , i'm trying understand , learn classes, have following class "daluser" doesn't have fields, methods, validatesession in folder called dal:

import com.app.be.beuser;  public class daluser{       public beuser validatesession(string user, string password)     {      ...     } 

i have class beuser has fields user , password , located in folder or package called be. particular type of class or common class despite not having fields?

what class without fields called?

there no universally applicable name this:

  • classes no fields have no explicit state, strictly speaking, every java object has state associated mutex. hence calling them "stateless classes" bit of stretch.

  • classes no fields may be "helper classes", absence of fields neither necessary or sufficient precondition.

  • an instance has no state immutable, call classes no fields "immutable classes" ... though locking use-case applies here too.

another distinction between helper classes , stateless classes whether class designed instantiated. helper class (in normal usage) consists of static methods, , not instantiated. (an instance serves no purpose). stateless class designed instantiated, , passed around other classes make method calls on instance; e.g. "policy object".

then there sub-case of "base class" use-case there no fields in base class. (in case, calling class "stateless" misleading, since there typically state in child classes.)

in short, need examine class , how being used determine label (or labels) best apply it.


in specific example, code best described stateless class. because designed instantiated , passed around in different contexts, functionality not depend on state of object itself.


here other examples illustrate why there no simple answer this.

1) helper class, has (static) field.

 public class plumbing {      private static nostapsfixed;      private plumbing() { }      public class fixtap(tap t) {          // fix 't'      }  } 

2) base class. has no fields, not intended helper class.

 public abstract class tradesman {      // no fields      public abstract invoice issueinvoice();  } 

3) here use of class no fields (java.lang.object) in way not "helper".

 final object mylock = new object();  ...  synchronized (mylock) {      ...  } 

4) , here example of class has no fields , not helper.

 public enum agreement {      yes, no  } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -