Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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 5481 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Posted 2005-02-24 08: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: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


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

There are no rules, KILER.

Cas Smiley

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2005-02-24 08: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: 51
Projects: 11


Monkey for a head


« Reply #3 - Posted 2005-02-24 09: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 10: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




Where's the Kaboom?


« Reply #5 - Posted 2005-02-25 00: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 Member




Java games rock!


« Reply #6 - Posted 2005-02-25 06: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 Member




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


« Reply #7 - Posted 2005-02-25 19: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 20: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 Member




Like a leaf in an icy world, memories will fade


« Reply #9 - Posted 2005-02-25 20: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
angelfaerie
Guest
« Reply #10 - Posted 2005-02-25 20:28:10 »

please can some one tell me can you create a game on java and how?
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #11 - Posted 2005-02-25 20:29:30 »

Quote
please can some one tell me can you create a game on java and how?


Can you please stop spamming?

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
angelfaerie
Guest
« Reply #12 - Posted 2005-02-25 20:30:02 »

noone talks to me
angelfaerie
Guest
« Reply #13 - Posted 2005-02-25 20:31:05 »

Spamming?
angelfaerie
Guest
« Reply #14 - Posted 2005-02-25 20:32:35 »

what does Jave do? it says it when i go on Runescape
angelfaerie
Guest
« Reply #15 - Posted 2005-02-25 20:33:53 »

Angry
angelfaerie
Guest
« Reply #16 - Posted 2005-02-25 20:34:50 »

I OWN this page
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #17 - Posted 2005-02-25 20:35:05 »

Someone, please, hand me the fscking ban hammer so I can slap this prebuscent 11 year old into internet oblivian.

angelfaerie, run to mommy and say that you are too young and too stupid to use the "internets."

Or another alternative:  For the love of humanity, take one for the team and shoot yourself in the face.  The world will be so much better off.

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
angelfaerie
Guest
« Reply #18 - Posted 2005-02-25 20:35:12 »

Angry
angelfaerie
Guest
« Reply #19 - Posted 2005-02-25 20:35:51 »

ive tried already
angelfaerie
Guest
« Reply #20 - Posted 2005-02-25 20:37:10 »

lemme gess ur 8 year old yer f**king bastard
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #21 - Posted 2005-02-25 20:37:38 »

Quote
ive tried already


If this is referring to shooting yourself in the face, it's a goddamned shame you didn't succeed.

Somebody with moderating/admining privledges, PLEASE IP ban this guy and delete all of his posts, and all of mine that respond to him.

Please.

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
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #22 - Posted 2005-02-25 20:39:20 »

Quote
lemme gess ur 8 year old yer f**king bastard


CLOSE  Grin

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
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #23 - Posted 2005-02-25 20:43:52 »

Quote

If this is referring to shooting yourself in the face, it's a goddamned shame you didn't succeed.


ROFL.

/me is already LOL at "For the love of humanity, take one for the team..."

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

Junior Member




Java games funk


« Reply #24 - Posted 2005-02-26 00:14:13 »

Please, someone with administrator privileges: change his avatar to one of eric CARTMAN.
That will do it for me Smiley
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #25 - Posted 2005-02-26 02:35:02 »

Back on topic.

I did say not to take the code literally, or maybe I should have said "example".

Regardless, getters and setters are sometimes evil.
High order functions such as "destroyWorld" should be legal, the way that I have shown.

When I write a program I only want to expose the most important features, doing so in a large program can lead to complexities such as the one I described above.

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

Jeff:
Unemployed. Wink
Offline Raghar

Junior Member




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


« Reply #26 - Posted 2005-02-27 15:05:36 »

Quote
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.


Just few words. Image processing library.

It looks more like Java.math than normal class. If I'd add spiders inside (they are better in different class) it might be over 3800 lines.

BTW I thinks java docs in source code are making the source code less readable, and unnecessary larger.  It would be much nicer if Javadocs would be GUI application that would write some external files and then merged them into documentation.
Offline Breakfast

Senior Member




for great justice!


« Reply #27 - Posted 2005-02-27 22:26:19 »

But if your javadocs were in external files and for whatever reason you just had the source code files, no matter how well written the code was it would be a good deal harder to interact with it.
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #28 - Posted 2005-02-28 09:15:37 »

If anyone gives you a size constraint, ignore them. In fact if anyone ever gives you any constraints, ignore them. Do what you have to do to make it work. Worry about making it fast later, and finally, when it's working and fast, worry about making it pretty enough to show off.

Cas Smiley

Offline erikd

JGO Ninja


Medals: 15
Projects: 4
Exp: 14 years


Maximumisness


« Reply #29 - Posted 2005-02-28 09:36:49 »

Heh, I have one class with 98617 lines and I'm 100% sure there's not one bug in it.  Grin

Pages: [1] 2
  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.

xsi3rr4x (27 views)
2014-04-15 18:08:23

BurntPizza (24 views)
2014-04-15 03:46:01

UprightPath (38 views)
2014-04-14 17:39:50

UprightPath (21 views)
2014-04-14 17:35:47

Porlus (36 views)
2014-04-14 15:48:38

tom_mai78101 (61 views)
2014-04-10 04:04:31

BurntPizza (119 views)
2014-04-08 23:06:04

tom_mai78101 (219 views)
2014-04-05 13:34:39

trollwarrior1 (186 views)
2014-04-04 12:06:45

CJLetsGame (193 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!