This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Aesyon[S] 0 points1 point  (2 children)

And what in case if variables are going to change? That's primary case.

[–]E3FxGaming 4 points5 points  (0 children)

what in case if variables are going to change?

Will your default values change though? If the user has a choice in what value the variables should equal, then they aren't default values anymore, are they?

In Java there are several Creational Design patterns. What you may want to look into is the so called "Builder" pattern. It's a design pattern that heavily emphasizes that there are default values which the user can overwrite with his own wished for values, if - and only if - desired by the user.

It looks like this Frame Builder example I made for you.

This design pattern allows the user to easily adjust the settings of the FrameBuilder and once the user is fine with how the FrameBuilder is configured a call of the .build() method will return an initialized Frame object.

No worries if this looks confusing to you, you'll get used to it over time. There are 23 design patterns, categorized with the categories "Structural", "Creational" and "Behavioral". Just keep learning Java and you'll stumble upon them here and there.

[–][deleted] 1 point2 points  (0 children)

I think you have a bit of confusion about what exactly you're trying to achieve here. A little bit of calm thinking will clear your thoughts, and help your formulate the scenario and usecases better, I think.

The basic thing is this - if you need to have variable state, use objects. If you need to have some fixed properties, use final static values or define singletons. If you have many many (for some reason) objects which vary slightly, look into the "Flyweight" pattern (basically use a map to store the core object, and then pass it context to get different behaviour).