Code Red > .NET

Overloading types.

(1/5) > >>

Bryco:
This overloading is you beaut, but it seems like sometimes you need a few extra choices.


--- Code: ---       
 static public Arc Arc(Point3d Cen,Vector3d V, double Rad,double startAng,double endAng,string sOwner) 
            //standard arc
 
        static public Arc Arc(Center Center, Point3d StartP, Point3d EndP, string sOwner)
        //3 point arc with center
   
        static public Arc Arc( Point3d StartP,Point3d MidP, Point3d EndP, string sOwner)
        //3 point arc
   
--- End code ---


Both the 3 point arc with center and the 3 point arc  have the same arguments so I was messing with making Center a class just to make it different than a Point3d, I would almost rather it was an enum but I can't figure that out.
Any ideas?

sinc:
This is a really heavy-handed reason for using a class, or even a struct.  For a case like that, I would tend to lean toward creating another method called Arc3P() or something like that.

If you want to use an enum, you could do that too, but it would require adding another argument to your command, which gets kind of messy:


--- Code: ---public enum ArcCreationMethod
{
    CenterAndEndpoints,
    ThreePointCurve
}

static public Arc Arc(ArcCreationMethod method, Point3d param1, Point3d param2, Point3d param3, string sOwner)
--- End code ---

Bryco:
I'm giving this a go, thanks.

Bryco:
So far it doesn't seem to work,
 Error   1   Type 'Util.AddEnt' already defines a member called 'Arc' with the same parameter types.
But I do like your Arc3P() idea.
string sOwner is a way to figure out if the item is to be added to Paperspace,modelspace,Currentspace or block.
This is where I started thinking about enums and while they work perfect for the first 3, I can't figure out how to pass either a stringname or an id for the fourth.   

MickD:
You are overloading your constructor correct?
If so, create a few constructors as you have but make sure you have a default ctor that takes no arg's. This way you can create a few arc creation methods that can return a new arc as a return type (as your ctor is really doing) and return a new arc to the 'null' arc you defined like-

Arc myarc;
myarc = Arc.Arc2pntAng(...);

In fact, you could simply call your arc create methods inside your ctors passing the param's as required that way you still have both choices to assign on definition or after you declare -

public Arc Arc(p1,p2,angle)
{
    return = Arc2pntsAng(p1,p2,ang);
}

// the method
public Arc Arc2pntsAng(p1,p2,angle)
{
    Arc tmparc = new Arc();
    tmparc = Arc2pntsAng(p1,p2,ang);
    return tmparc;
}

<edit> added ctor and method

you may have to make the class methods static though and you will still have only limited ctor's but at least you still have a way to create different methods. Perhaps not create ctor's at all and just enforce the creation??
It's only food for thought though, it's been a while with c# :)

hth.

Navigation

[0] Message Index

[#] Next page

Go to full version