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 16 MB 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. 
|
|
|
princec
|
 |
«
Reply #1 - Posted
2005-02-24 08:34:05 » |
|
There are no rules, KILER. Cas 
|
|
|
|
kevglass
|
 |
«
Reply #2 - Posted
2005-02-24 08:44:27 » |
|
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!
|
|
Orangy Tang
|
 |
«
Reply #3 - Posted
2005-02-24 09:50:45 » |
|
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.
|
|
|
|
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... 
|
|
|
|
swpalmer
|
 |
«
Reply #5 - Posted
2005-02-25 00:17:13 » |
|
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...  I have to check with work if there is a security problem with our network. It looks like you have been reading my code ;-)
|
|
|
|
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 
|
When do I get my makeMyGameAsILike() extension?
|
|
|
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.
|
|
|
|
|
blahblahblahh
|
 |
«
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...
|
|
|
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. 
|
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!
|
|
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?
|
|
|
|
|
Virum
Junior Member  
Like a leaf in an icy world, memories will fade
|
 |
«
Reply #11 - Posted
2005-02-25 20:29:30 » |
|
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 » |
|
|
|
|
|
|
angelfaerie
Guest
|
 |
«
Reply #16 - Posted
2005-02-25 20:34:50 » |
|
I OWN this page
|
|
|
|
|
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 » |
|
|
|
|
|
|
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
|
|
|
|
|
Virum
Junior Member  
Like a leaf in an icy world, memories will fade
|
 |
«
Reply #21 - Posted
2005-02-25 20:37:38 » |
|
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
|
|
|
Virum
Junior Member  
Like a leaf in an icy world, memories will fade
|
 |
«
Reply #22 - Posted
2005-02-25 20:39:20 » |
|
lemme gess ur 8 year old yer f**king bastard CLOSE 
|
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
|
|
|
blahblahblahh
|
 |
«
Reply #23 - Posted
2005-02-25 20:43:52 » |
|
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...
|
|
|
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 
|
|
|
|
|
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. 
|
|
|
Raghar
Junior Member  
Ue ni taete 'ru hitomi ni kono mi wa dou utsuru
|
 |
«
Reply #26 - Posted
2005-02-27 15:05:36 » |
|
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.
|
|
|
|
|
Breakfast
|
 |
«
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.
|
|
|
|
|
princec
|
 |
«
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 
|
|
|
|
erikd
|
 |
«
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. 
|
|
|
|
|