Yes, indeed it is an object, wrong use of terminology on my part. I'm
going to need to take a look at the Delegate pattern. If that is what
I'm using it was totally unitentional. Anyways, I guess my concern is,
if we look at this a little deeper, suppose we have two classes A & B
again. We then instantiate an object of class A. Suppose there is a
function from class A ( func1 ) that calls another function from class
B ( func1 ) so we must pass an object of class B as argument to the
function in class A. Now say for instance the function of class B turns
back around and calls a function from class A ( func2 ) and does
something in turn on the original class A object using the keyword this
as an argument to func1 of class B. Is this methodology sound. It seems
as though the indirect nature of function calls in this situation isn't
good design, but for whatever reason I can't see any other way around
it. The reason is because there are many class B's derived from an
abstract class type that knows how to handle the function call func1
polymorphically and we can handle the manipulation of an object
instance of class A accordingly.
class A {
func1 ( B b ) {
b.func1( this );
}
func2() { };
}
class B {
func1 ( A a ) {
func2( a );
}
}
jmcgill wrote:
> wrote:
> > Is it bad programming practice to pass a class as an argument
>
> You are passing an Object of type B in your example, not a "Class" as I
> read your question. (It is possible and fairly common in some
> situations to pass a Class Object).
>
> You are passing an object to a method which performs operations on that
> object. There's nothing wrong with this. Would you expect people to
> criticize a method that takes a String argument, for doing String
> operations on that argument?
>
> > class A {
> > func1 ( B b ) {
> > b.func1();
> > }
> > }
> >
> > class B {
> > func1 ()
> > }
>
> Depending on what you're doing, I might call that either a Delegate or a
> Decorator.