Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:23:01+00:00 2026-06-14T00:23:01+00:00

I am just jumping into C# from Java on the recommendation of my uncle.

  • 0

I am just jumping into C# from Java on the recommendation of my uncle. The Java geometry lib seems more complete than C#’s Drawing lib, so I am working on a simple bit of porting with a small bit of added functionality to begin into C#.

However, I have run into a design issue and cannot discern which would be the better choice. To have multiple methods in the abstract base class that take concrete datatypes OR to have less methods that take the abstract base as its argument?

public abstract bool isOverlapping(GeometricObject2D o) {}

OR

public abstract bool isOverlapping(Rectangle2D rect) {}
public abstract bool isOverlapping(Circle2D circ) {}
etc...

The argument I am having in my head tells me concrete arguments prevent logic errors, BUT, I have been taught to always use abstract datatypes if the use fits.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:23:03+00:00Added an answer on June 14, 2026 at 12:23 am

    If you want to put the operation in the base class, use the abstract type. You don’t want to have to modify the base class every time you decide to add a new subclass.

    An alternative is to use something like the visitor pattern and have each concrete class dispatch in turn to the visitor. An intersection visitor would then contain all the knowledge of how to compute the intersection of each pair of object types.

    Here’s how the visitor pattern can be used for this. (I’ll use Java syntax since I’m not a C# programmer). First, using the visitor pattern here is more complicated than the usual case because you have to modify the operation based on the types of two arguments. In effect, you need triple dispatch. Languages like Clojure support this directly, but in Java (and probably C#) you need to simulate triple dispatch by using two levels of visitor. It’s ugly, but the great benefits are that it keeps your geometry hierarchy clean and maintainable, and it centralizes all intersection logic in one compilation unit.

    public interface IGeometry {
        void accept(IGeometryVisitor visitor);
    }
    
    public interface IGeometryVisitor {
        void visitCircle2D(Circle2D circle);
        void visitBox2D(Box2D box);
        // a method for each concrete type
    }
    
    public class Circle2D implements IGeometry {
        public void accept(IGeometryVisitor visitor) {
            visitor.visitCircle2D(this);
        }
    }
    
    public class Box2D implements IGeometry {
        public void accept(IGeometryVisitor visitor) {
            visitor.visitBox2D(this);
        }
    }
    
    public class IntersectionVisitor implements IGeometryVisitor {
        private boolean mResult;
        private IGeometry mGeometry2;
    
        public static boolean isOverlapping(IGeometry geometry1, IGeometry geometry2) {
            return new IntersectionVisitor(geometry1, geometry2).mResult;
        }
    
        private IntersectionVisitor(IGeometry geometry1, IGeometry geometry2) {
            mGeometry2 = geometry2;
            // now start the process
            mGeometry1.accept(this);
        }
    
        public void visitCircle2D(Circle2D circle) {
            mGeometry2.accept(new Circle2DIntersector(circle));
        }
    
        private class Circle2DIntersector implements IGeometryVisitor {
            private Circle2D mCircle;
            Circle2DIntersector(Circle2D circle) {
                mCircle = circle;
            }
            public void visitCircle2D(Circle2D circle) {
                mResult = isOverlapping(mCircle, circle);
            }
            public void visitBox2D(Box2D box) {
                mResult = isOverlapping(mCircle, box);
            }
        }
    
        private class Box2DIntersector implements IGeometryVisitor {
            private Box2D mBox;
            Box2DIntersector(Box2D box) {
                mBox = box;
            }
            public void visitCircle2D(Circle2D circle) {
                mResult = isOverlapping(circle, mBox);
            }
            public void visitBox2D(Box2D box) {
                mResult = isOverlapping(mBox, box);
            }
        }
    
        // static methods to compute overlap of concrete types
        // For N concrete types there will be N*(N+1)/2 methods
        public static boolean isOverlapping(Circle2D circle1, Circle2D circle2) {
            return /* intersection of 2 circles */;
        }
    
        public static boolean isOverlapping(Circle2D circle, Box2D box) {
            return . . .;
        }
    
        public static boolean isOverlapping(Box2D box1, Box2D box2) {
            return . . .;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been jumping from C# to Java an awful lot and the differences between
Just recently I've installed the Qt libraries on my computer, and as a complete
just wanted to ask where I define initial class properties? From other languages I
Just see this: SELECT clientid,clientname,startdate,enddate,age FROM clients WHERE clientid IN (1,2,3,4,5) AND CASE WHEN
A shopping cart application I'm working on jumps domain when it goes from the
I'm jumping into Ruby on Rails with Agile Web Development with Rails. I got
i have a problem with getting content from a XML into a mysql database.
I'd like to learn some Javascript before jumping into a framework like jQuery or
I have noticed lately that the Visual Studio 2010 debugger keeps jumping into this
Ok, so I'm a little new to DevExpress and I'm jumping into the middle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.