Mav986
Mav986

Reputation: 1

What are the different types of java classes?

I'm new to SO, so if I've done this wrong, please point me in the right direction.

I think this is a bit of an awkward question, because I'm not so great at articulating my thoughts.

At university, we are taught that a java class which is written to be an object, with constructors, getters, setters, etc, are called "Container Classes". They contain data about themselves(a name attribute, for instance).

My question is what are other types of classes? For instance, you have to have a class where you create and manipulate your objects. For a small program this isn't a problem(just put it into the main class/method). For a larger program this would be silly and unmanageable, so obviously you create other classes. I've taken to naming mine "Handler"s. I have a "FileHandler" an "ObjectHandler", etc.

What type of class are these? Are there other class types out there?

Edit: To clarify, I'm wondering about what to call a category of classes, such as classes that are designed to do specific things. Helper classes? Utility classes?

Final Edit: I answered my own question here: https://stackoverflow.com/a/43964279/7985805

Upvotes: 0

Views: 1391

Answers (3)

Mav986
Mav986

Reputation: 1

So it turns out after a bit of research, the "class types" I was trying to find names for are actually called "Design Patterns". Things like Builders, Factories, Adapters, etc.

I found a handy tutorial explaining them in further depth here: https://www.tutorialspoint.com/design_pattern/design_pattern_overview.htm

Thanks for trying to answer my very badly worded question. As I said, I'm terrible at trying to explain what I want to say.

Upvotes: 0

Ousmane D.
Ousmane D.

Reputation: 56423

At university, we are taught that a java class which is itself an object

I would have to disagree here, classes are templates for objects, you can think of them as containing a description of a particular object i.e. the object states, the behaviours that object can perform etc. An object is an instance of a class thus a class is not an object.

My question is what are other types of classes?

A class can be any type, it just depends on what you're attempting to accomplish e.g. when making a space invaders game, you could have a class of type Alien(enemies), a class of type Defender(the shooter), a class of type Bullet which the Defender can use to shoot the Aliens etc.

Upvotes: 3

M. Haverbier
M. Haverbier

Reputation: 383

In my opinion if you call 'classes' 'container classes' you are only adding a redundant word.

In larger programs there could be some kind of classes that have the same purpose, e.g there could be ModelData classes, which only hold data: like employee, contract, ComplicatedCalculationResult; or there could be handler classes: FileHandler, MouseHandler, ... But all this is not set to a fixed wording.

You can name your class as it seems fit. At best name it so that someone else can guess what the class is for.

Upvotes: 0

Related Questions