Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java code in other file

Reply
Thread Tools

java code in other file

 
 
vertigo
Guest
Posts: n/a
 
      04-09-2004
Hello
I have quite complicated class, and i would like to move
one method's body of this class to other file ?
Is it possible ? How ?

Thanx
Michal

 
Reply With Quote
 
 
 
 
Bjorn Abelli
Guest
Posts: n/a
 
      04-09-2004

"vertigo" wrote...

> I have quite complicated class, and i would like
> to move one method's body of this class to other file ?
> Is it possible ? How ?


If you mean to separate the one class into several sourcefiles, I don't
think thats possible.

On the other hand, who knows what's coming up in the future (I believe that
this option will be available in next version of .NET/C# for instance).

However, if you have a too complicated class, there's a possiblity that your
design of it could improve through abstraction, and hence actually separate
the methods between more classes.

"Static" methods are often possible to separate to other classes, but with
instance methods the only way is through some kind of abstraction.

To give a *small* example:

Say you have this class:

class A
{
void first() { ... }
void second() { ... }
}

You could separate the methods with this design:

abstract class Abstract
{
void first() { ... }
}

class A extends Abstract
{
void second() { ... }
}

Without looking at the actual code I can't really tell, but in my experience
a complicated class or method is often the result of not using patterns for
low coupling and high cohesion, e.g. polymorphism.

just my 2c

// Bjorn A




 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-10-2004
On Fri, 09 Apr 2004 12:16:20 +0200, vertigo <(E-Mail Removed)> wrote
or quoted :

>I have quite complicated class, and i would like to move
>one method's body of this class to other file ?
>Is it possible ? How ?


If a class is getting too big, best to think about how to simplify.

Techniques you might use.


1. a core class with a derived class. The core class has accessors.
The derived class has the business logic. This makes it easier to
later create other variants sharing a common core.


2. Split off some of the fields as separate object with a reference to
it. If for example you had a Dog class with a huge amount of detail on
the dog's stomach, you could split off a Stomach class, even though
all dogs have exactly one stomach.


3. Split off the static methods into their own class.

4. Have you created a "Processor" class with a switch to determine
"food" or "word" mode? If so, create two separate classes.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Jim
Guest
Posts: n/a
 
      04-12-2004
Not to detract from Roedy's useful suggestions, but I believe the short
answer is no (reason being someone forgot to include a preprocessing step
with Java.)

One solution would be to put the complete function in interest in it's own
file as the sole method in a new class, the remainder of the original in its
own file as another class, then have one extend the other.

Hope it helps.

Jim Cant


"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Fri, 09 Apr 2004 12:16:20 +0200, vertigo <(E-Mail Removed)> wrote
> or quoted :
>
> >I have quite complicated class, and i would like to move
> >one method's body of this class to other file ?
> >Is it possible ? How ?

>
> If a class is getting too big, best to think about how to simplify.
>
> Techniques you might use.
>
>
> 1. a core class with a derived class. The core class has accessors.
> The derived class has the business logic. This makes it easier to
> later create other variants sharing a common core.
>
>
> 2. Split off some of the fields as separate object with a reference to
> it. If for example you had a Dog class with a huge amount of detail on
> the dog's stomach, you could split off a Stomach class, even though
> all dogs have exactly one stomach.
>
>
> 3. Split off the static methods into their own class.
>
> 4. Have you created a "Processor" class with a switch to determine
> "food" or "word" mode? If so, create two separate classes.
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any tool to convert java raw code (a la java 1.4) into generics code Royan Java 8 02-15-2008 02:35 PM
Creat a DLL File from python code, and use that DLL file in other Platform (Labview, Java .NET etc) macedo.silva@gmail.com Python 2 03-09-2007 05:52 PM
Another Question: Java and other application, Java and hardware Roberto Faenza Java 4 02-25-2007 06:18 PM
How to access web.sitemap file from other virtual directories other than the current application root folder? hvajja@gmail.com ASP .Net 0 08-07-2006 08:26 PM
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM



Advertisments