Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Shortcuts in OOP  (Read 6083 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Duke




Java games rock!


« Posted 2005-02-24 07:02:32 »

I tend to use composition everywhere I can, with a touch of inheritence to make life easier.

Example:
1  
2  
3  
4  
private final FortressCollection forts;
private final GruntCollection johnFarnham;
private final MaterialResources resources;
private final SubAtomicConverter converter;


*NOTE: These classes are final being only a single instance is ever accepted, in the constructor.*

Each of these classes have about 168 methods(operations) due to delegation of reference types.
The classes are in their own files and each file weighs in an estimated 16MB of space. The files only contain code.

Instead of writing so many delegates, you can just do this:
1  
converter.getPowerSource().getPowerMineral().getNeutronics().getDuressType().getUltimateWeapon().destroyWorld(WorldAddress address);


*NOTE: "WorldAddress" is an enum.

Delegates should only be used in circumstances which reflect important top level functions, not for every bleeding method from every other reference type.

OOP states specifically that by using getters for reference types, you are breaking the rules.
When will OOP rules change to reflect the shortcut?

Sun have no problem breaking the rules though, I've seen non static getters from Sun's classes to other reference types in Sun's own libraries.

This is an outrage, why am I stuck obeying the rules when everyone else breaks the rules?

Example of a well written delegate:
1  
2  
3  
public void destroyWorld(WorldAddress address){
converter.getPowerSource().getPowerMineral().getNeutronics().getDuressType().getUltimateWeapon().destroyWorld(WorldAddress address);
}


*The code in this post is an example and should not be taken literally.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline princec

JGO Kernel


Medals: 409
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2005-02-24 07:34:05 »

There are no rules, KILER.

Cas Smiley

Offline kevglass

JGO Kernel


Medals: 191
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2005-02-24 07:44:27 »

Quote

OOP states specifically that by using getters for reference types, you are breaking the rules.
When will OOP rules change to reflect the shortcut?


It does? I thought generally OOP gave you a set of tools that helped you to build maintainability. testability and reliability. How you use them is entirely up to you.

The rule of thumb if any seems to be "as long as you can justify it to yourself and your peers its ok".

Incidently, for your particular problem you might consider looking at Mixins which Java doesn't support but languages like Ruby do.

Kev

PS. If you've got 168 methods in an interface fascade I'd suspect your design may be slightly faulty.

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

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2005-02-24 08:50:45 »

Quote

Incidently, for your particular problem you might consider looking at Mixins which Java doesn't support but languages like Ruby do.

Nice (an extension to the Java language) supports them, but I havn't had chance to look at the language as a whole yet.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline EgonOlsen
« Reply #4 - Posted 2005-02-24 09:12:11 »

If you have the feeling that something you're doing is ugly in one way or the other, but you still want to do it (because you are lazy, because it's faster...whatever), just write a

@todo: Change this!

comment. We all know, that you'll never touch this code again, but you are feeling much better that way... Grin

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #5 - Posted 2005-02-24 23:17:13 »

Quote
just write a

@todo: Change this!

comment. We all know, that you'll never touch this code again, but you are feeling much better that way... Grin


I have to check with work if there is a security problem with our network.  It looks like you have been reading my code ;-)

Offline Middy

Junior Duke




Java games rock!


« Reply #6 - Posted 2005-02-25 05:33:49 »

Well I tend to use @fixme : this stinks or @optimizeme this could be done faster

I never touchy it again Smiley

When do I get my makeMyGameAsILike() extension?
Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #7 - Posted 2005-02-25 18:46:06 »

168 methods? Wimpy. I have a class with over 3000 lines of code.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2005-02-25 19:10:35 »

In java, no class should ever be more than 1000 lines of code, including all comments and all javadocs.

Entirely IMNSHO, of course, but from long experience, and lots of code reviews over the years, I've found the sweet spot is that any class with more than 750 lines of code is almost certainly "wrong" or "broken": if you ever hit 1000 lines, you know something is DEFINITELY wrong.

Shrug. Just a tip.

malloc will be first against the wall when the revolution comes...
Offline Virum

Junior Duke




Like a leaf in an icy world, memories will fade


« Reply #9 - Posted 2005-02-25 19:27:04 »

I'm with blah^3 here.

My average class length is 200-300 lines.  I have some classes as small as 10-30.

Yes, I like my classes small and manageable. Smiley

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Blog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 161