#Help with organizing

25 messages · Page 1 of 1 (latest)

drifting tusk
#

If I'm trying to follow SOLID principles and I have a hierarchy like this

Punishment > PardonablePunishment > TemporaryPunishment

Should I do this with abstract classes or interfaces?

I have a lot of fields to create like this:

UUID target;
Issuer issuer;
Reason reason;
Duration duration;
...

And the last field I have is a Punishment Type which is an enum. The only reason I have this enum is because im saving data with GSON. Each enum looks like this:

Type.BAN(Ban.class)
Type.MUTE(Mute.class)

I need this so when I deserialize json, I'm able to link back which Punishment is which class.
And I feel like there's a lot better of a way to do this but I'm unsure.

oblique streamBOT
#

This post has been reserved for your question.

Hey @drifting tusk! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sudden inlet
#

if you want to specify having fields, then you can't use an interface

bright violet
#

I'd say abstract classes would be the best bet, especially for later use. I mean, if you want to, say, create a new punishment with the name 'VeryBadPunishment', it would 'make more sense' to write 'extends Punishment' vs 'implements Punishment'.

oblique streamBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

meager marten
drifting tusk
#

so basically when I serialize with gson

#

It's not possible to tell which class this json belongs to

#

Unless I have a Punishment type

meager marten
meager marten
drifting tusk
#

The serialized info looks like this

"target": "uuid", "timeIssuer": long, etc

#

Casting won't work

#

classes like

Mute and Ban will have identical information, but different meanings

meager marten
drifting tusk
#

Yes

meager marten
#

Then what about pardonable and temporary

drifting tusk
#

It' was a possible idea

#

Here's what my original hierarchy looked like

#

Punishment > PardonablePunishment > TemporaryPunishment

#

and then Ban and Mute extends TemporaryPunishment

meager marten
#

Trying to get more idea on what u want to do

oblique streamBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.