Shortcuts in OOP

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

Example:


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:

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:


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.

There are no rules, KILER.

Cas :slight_smile:

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.

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

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… ;D

[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… ;D
[/quote]
I have to check with work if there is a security problem with our network. It looks like you have been reading my code :wink:

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

I never touchy it again :slight_smile:

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

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.

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. :slight_smile:

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

[quote]please can some one tell me can you create a game on java and how?
[/quote]
Can you please stop spamming?

noone talks to me

Spamming?

what does Jave do? it says it when i go on Runescape

:frowning:

I OWN this page

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.

:frowning:

ive tried already