Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Managing Relationships  (Read 1554 times)
0 Members and 1 Guest are viewing this topic.
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Posted 2012-10-13 04:29:08 »

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?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2012-10-13 13:46:16 »

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.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline ags1

JGO Ninja


Medals: 55
Projects: 2
Exp: 5 years


Make code not war!


« Reply #2 - Posted 2012-10-13 18:47:51 »

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!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rorkien
« Reply #3 - Posted 2012-10-13 19:31:16 »

Obligatory image

Click to Play
Offline ags1

JGO Ninja


Medals: 55
Projects: 2
Exp: 5 years


Make code not war!


« Reply #4 - Posted 2012-10-13 19:33:48 »

Don't listen to Rorkien... Refactor! Refactor! Refactor!

Offline KittenKoder

Senior Member


Medals: 7



« Reply #5 - Posted 2012-10-13 19:44:07 »

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.

I am no one else.
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #6 - Posted 2012-10-13 20:51:44 »

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.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-10-13 20:53:30 »

Offtopic since you mentioned you had to back up your code:

Look into Mercurial or Git. They are versioning systems that help you track each change you make to your code.

This is a good explanation of how Mercurial works.

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2012-10-13 20:53:50 »

Hehe, kittens.

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-10-13 20:54:17 »

Hehe, kittens.
They are why I waste SO MUCH TIME on Reddit Sad

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #10 - Posted 2012-10-13 20:58:27 »

Thats what I meant by I backed up my code. Sorry for not being clear.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-10-13 20:59:13 »

Thats what I meant by I backed up my code. Sorry for not being clear.
Ah ok that's good! Smiley

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 784
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2012-10-13 22:02:34 »

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

...
Go read Martin Fowler's 'Refactoring' book
...

... and another aspiring indie developer lost to design patterns and the art of code perfection. Emo



What to do instead?
  • get it to work
  • get it fast enough
  • polish it
  • bring it to market

Nobody in the game scene cares about code quality, they care about the product.

If that takes a super big Manager class with a dozen static methods, by all means do it, because it's easy to write, and manage.

In the next project, try to not make the same mistakes - that's all there is to improving your code.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Rorkien
« Reply #13 - Posted 2012-10-13 22:18:25 »

Offtopic since you mentioned you had to back up your code:

Look into Mercurial or Git. They are versioning systems that help you track each change you make to your code.

This is a good explanation of how Mercurial works.

Right-Click file on Eclipse > Compare With > Local History  Yawn

Not as spicy, detailed and clear as Git, but it has saved my skin (with a single click) a couple times
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #14 - Posted 2012-10-13 22:31:55 »

Right-Click file on Eclipse > Compare With > Local History  Yawn

Not as spicy, detailed and clear as Git, but it has saved my skin (with a single click) a couple times
Yeah, that's why I don't like/use it Tongue

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!