Usually a 'Controller' is the interface between a user interface component and a model (e.g. Purchase). Controllers should be thin classes, doing little more than mapping user interface events to model functions.
A 'Manager' is a code smell. The purchase should manage itself, or it could be managed by an owning class, like Vendor or Buyer.
A 'Handler' is usually a single function wrapped in an object. These are needed when programming in legacy languages without first-class functions.
To overload a method with a new method, the new method should have a different signature. I.e. two overloaded methods have the same name, but different parameters. Here's an example of two overloaded methods:
boolean isOdd(int number) { ... };
boolean isOdd(float number) { ... };
Based on the parameter types, the corresponding method will be called. Note that changing the return type is not enough (though you can do this additionally).
When a method is overridden, then the new method has the same signature and replaces the overridden method in some cases. Here's an example of an overridden method:
public class A
{
public void someMethod() { ... }
}
public class B extends A
{
public void someMethod() { ... }
}
The choice is made based on the object type. For example,
A someA = new B();
someA.someMethod();
will call the someMethod
of B
. You can (and should) add the @Override annotation:
public class B extends A
{
@Override
public void someMethod() { ... }
}
Now, if you accidentally change the parameters in B, the compiler will inform you, that you are not overriding someMethod() but overloading it.
Best Answer
In order for a class to be instantiated it has to be loaded by the classloader...in many cases this is the first time the class has been just-in-time compiled. If you access a static variable on a class, it has to be loaded. If you want to reflect on a class it has to be loaded. There are many circumstances where you might just load a class rather than instantiate.
Also the static initializer(s) for a class fire the first time the class is loaded (and before anything else). If you have an explicit static intializer you can use it to perform a global initialization if need be.