So I'm making game, and all of a sudden I want to refactor. So, I start refactoring, and these refactors are a key part of the game's structure. Having deleted the old classes and preparing for a new Manager class that was missing before, I hit a roadblock. I have 3 (maybe four) main class types. I have Blocks, Entities, Items, and Script(s). This Manager class will be awesome, but I have to understand one thing first:

How do my types relate? Or: How do I want my types to relate?

I'm not exactly sure where to go with this. I want to design something that is flexible, but without unnecessary coding. I'm not sure how to visualize this, but I get the idea that a flowchart would be a good medium.

Anyways, how do you guys do it? Do you just jump in and program it? Or do you plan it out?

Having deleted the old classes and preparing for a new Manager class that was missing before

That's not refactoring. That's deleting code and rewriting it.

Quote

How do my types relate? Or: How do I want my types to relate?

That's up to you. Decide which are the lower level types and which are the less low level ones that will depend on them. How you decide that depends on which bits will change most, which bits are most generally applicable, and which bits do you expect to extend most.

Quote

Anyways, how do you guys do it? Do you just jump in and program it? Or do you plan it out?

Go read Martin Fowler's 'Refactoring' book - what you're doing is not refactoring, you're throwing it out and starting again. That's exactly the wrong thing to do and ignores all the good stuf you get when you refactor things properly. Refactoring should be a sequence of small, simple operations that move you towards a better design.

As an aside, monolithic 'Manager' classes are almost always bad design, and something you should refactor away from, not towards.

Refactoring starts from the principle that new code is worse than old, mature code. You make the old code better by making small changes rather than making a lot of new code with new bugs.

Refactoring is not just bug fixing: you have some kind of long-term plan for how you want to improve the code (for example, remove cyclical dependencies, or break up a few bloated methods) and is always a good idea!

Well, first off, always plan out what you are going to do before you do it, saves headaches and bruises on the forehead of yourself and anyone who ventures into that code. The idea behind any good code is "set it and forget it," in other words, you do it right the first time so you aren't restructuring your packages every single edit. Refactorinig should be used to refine the code, not revamp it, so there's a flaw.

I was debating posting a response here because it will hurt feelings with what I have to say, but, if you're deleting completed classes then you're doing it wrong. I refactor all the time, but I only delete classes that I create as place holders, in case I might need it only to discover it will complicate matters more, thus the classes I delete were never implemented in the first place and nothing else needs changing to accommodate it's disappearance. I recommend you find a method of planning that helps you eliminate the need for class deletion, but nothing will eliminate the need for refactoring.

Ok. Well, my code is backed up just In case I decide the old code was better. But I feel like my old way of doing things was sloppy. The new class is going to be a manager. It's main purpose is to bind together the core parts of the game, and allow other classes to access core information easily. For example, the manager will allow class to get the player entity, or get the block at a certain position.

Also, I like to simplify everything. I try to have the least amount of classes and and the greatest amount of flexibility.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org