The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Cyclic Dependency !

Posted by N. Ganapathy Subramanian on January 08, 2001 at 2:06 AM

> Hi

> I am getting better at OOP design but far from an expert!
>
> However, I would recommend you don't design your classes in this way (!) Would it not be better to have a super class of both worker and manager (employee, say). The shared methods that apply to both go in the super class, the methods particular to managers and workers go in those respective sub-classes.

> If you give me more info about the functions you wish to implement I could try to help further...

> regards

> richard


Hi richard,

Thanks for your suggestion.

This works only for classes which are co-related. There are situations when both the classes would not be logically related, but depend on each other. I will tell a specific case in my project so that it would be much clearer.

Consider two classes

1) BOException

Is a specific Exception class derived from 'Throwable' (i.e. BOException extends Throwable). This is a custom exception class which contains some of the transaction information (like connection name, username, userid etc.).

2) BOTransaction

Is a transaction class containing transaction details

As per case 1), since BOException contains transaction information it depends on BOTransaction.
As per case 2), since BOTransaction needs to handle Exception within itself it depends on BOException.

Now we have a situation where we have two dependend class which are not logically related. I am not sure whether we could apply a super class to solve the above.

Observed - The same situation may get solved in C++ by using forward declaration within each class. We cannot achieve the same in Java since we dont have the concept of diffrentiating header file (*.h) and source file (*.cpp).

Thanks & Regards
N. Ganapathy Subramanian



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us