Passing arguments between classes - use public properties or pass a properties class as argument?

Posted by devoured elysium on Stack Overflow See other posts from Stack Overflow or by devoured elysium
Published on 2010-04-07T14:38:01Z Indexed on 2010/04/07 14:43 UTC
Read the original article Hit count: 198

So let's assume I have a class named ABC that will have a list of Point objects.

I need to make some drawing logic with them. Each one of those Point objects will have a Draw() method that will be called by the ABC class.

The Draw() method code will need info from ABC class.

I can only see two ways to make them have this info:

  1. Having Abc class make public some properties that would allow draw() to make its decisions.
  2. Having Abc class pass to draw() a class full of properties.

The properties in both cases would be the same, my question is what is preferred in this case. Maybe the second approach is more flexible? Maybe not? I don't see here a clear winner, but that sure has more to do with my inexperience than any other thing.

If there are other good approaches, feel free to share them.

Here are both cases:

class Abc1 {
    public property a;
    public property b;
    public property c;
    ...
    public property z;

    public void method1();
    ...
    public void methodn();
}

and here is approach 2:

class Abc2 {
    //here we make take down all properties

    public void method1();
    ...
    public void methodn();
}

class Abc2MethodArgs {
    //and we put them here. this class will be passed as argument to
    //Point's draw() method!
    public property a;
    public property b;
    public property c;
    ...
    public property z;
}

Also, if there are any "formal" names for these two approaches, I'd like to know them so I can better choose the tags/thread name, so it's more useful for searching purposes. That or feel free to edit them.

© Stack Overflow or respective owner

Related posts about c#

Related posts about java