0

I am confused on how to do this from an object oriented perspective with maintainability in mind. I was taught when designing an application to always think about change. So I am trying to spend some time on a personal project for design, heck I may want to change it later. The application was inspired by the newest game called Division. It will be a calculator for damage per second.

The technologies I have chosen are Spring, REST, Hibernate, Angular.js 1.0 and maven. Possibly bootstrap but I am unsure at this moment because I am only focusing on the back end. These technologies I understand aren't really needed for this level application but I am doing it for learning purposes.

Now since you have some what of an understanding of what the project is, now the issue I am having. I am having a hard time making the server object oriented with regards to the POJO.

In the division we have weapons and gear. Weapons can have different mods and attributes. Not all weapons can have the same mods such as an Assault Rifle can have a scope but why would a shotgun have a scope? The attributes are relative the same for weapons but the mods vary depending on the type of weapon used. For the gear, gear can have different attributes based on the type of gear it is. Gloves can have attributes that increase critical hit chance while the backpack has an attribute that increases ammo capacity. The gloves can't have an attribute of ammo capacity and the backpack can't have critical hit chance.

Both gloves and the backpack are gear but not the same type of gear. Same thing for weapons, both the assault rifle and shotgun are weapons but not the same type of weapon. I thought about creating a super class called gear and weapon and then subclassing the different weapons/gear. I am confused on how to do this from a professional perspective and as the best learning experience for design.

1
  • In the same way as you do your description, you can create a model image, that represents these associations/relationships. Start as easy as possible, but try to include all "entities". With this entity relationship model, you can visually deduce the object model you want to work with in the application. Commented Apr 19, 2016 at 13:50

2 Answers 2

1

This looks like a use case for Decorator pattern .

Do go through the link: https://sourcemaking.com/design_patterns/decorator

It even has a similar example using weapons.

Basically decorated is used when we want to add additional properties to an object dynamically.

Create an decorator of type say ModDecorator(base class) and have specific mods extend it . Now dynamically you can ad these mods to your weapons .

I am not very familiar with the types of Mods/Weapons/gear/Attributes so am unable to give a specific answer but do go through the link.

Sign up to request clarification or add additional context in comments.

1 Comment

Decorator will fit what I need perfectly. Thank You, Great resource by the way. I am bookmarking it.
0

The initial idea to have a weapons and gear super class sounds exactly like a good practice for design.

As for mods you could add a property to the weapon as list of properties for mods and look into using generics and interfaces to limit which type of gun can have which kinds of mods.

Something like a property of type scope for all subclasses of the rifle class and so on for other mods.

It might be a good idea to look into this in terms of the object equipping the items as well.

How is the base damage affected?
Who holds the base damage?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.