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 7730861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:20:04+00:00 2026-06-01T06:20:04+00:00

Suppose I was designing a component representing grips on a UI control for resizing

  • 0

Suppose I was designing a component representing grips on a UI control for resizing it.

Control

now obviously each grip is not exactly the same in terms of behavior, for instance the top left grip will have to display a North West South East mouse cursor and dragging it will change the size of the control whereas the top middle grip needs to show a north south mouse cursor and dragging it will only allow you to change the height.

In terms of implementation there are two basic approaches:-

(1) a constructor which requires you to pass in information as to what kip of grip you are designing and then have a huge switch statement inside to define the actual behavior of the grip like so :-

- initWithGripType(int)gripType
{
    switch(gripType {
        case TOP_MIDDLE_GRIP:
            cursorType = northSouthCursor;
            draggedMovement = upDown;
            break;
        case TOP_LEFT_GRIP:
            cursorType = northWestSouthEastCursor;
            draggedMovement = upDownLeftRight;
            break;
        ...
        ...
        ...
    }
}

(2) have a grip base class that defines the common attributes. e.g painting a grip is the same no matter which grip it is. And then sub classes for each grip type liks so :-

@interface Grip : NSObject {
    NSCursor _cursorType;
    int _draggedMovement;
}

// force init to be unavilable for base class
- (id)init __attribute__((unavailable("Instantiate subclass instead.")));
- (void)drawGrip;

@end;



@interface GripTopLeft : Grip {
}

- (id)init;

@end;

@interface GripBottomLeft : Grip {
}

- (id)init;

@end;

...
...
...

Approach two has the advantage that I don’t have to maintain any switch statements and can add new grip types at will, the downside is that if I have many grip types, each one is now a separate source and header file.

Is there a third approach?

  • 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-01T06:20:05+00:00Added an answer on June 1, 2026 at 6:20 am

    There are lots of ways to implement this as a single class without having to use an unwieldly switch statement. Here are two:

    • Use convenience methods (i.e., factory methods) to get different gripTypes
    • Use an NSDictionary instead of a switch statement to set up a grip’s properties based on its type

    I would lean towards keeping it in one method, because if you want to customize the behavior of Grip by subclassing, with your second approach you’d have to write another subclass for each type, or revise your class hierarchy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you are designing a PC game that keeps track of high scores. In
Suppose I am designing a class that can handle any database technology to create
Suppose I have multiple roles, each one defining a set of items: package A;
I need help designing a SQL table. Suppose I have cardnumber , cardtype ,
Suppose I were designing a web service with modest security requirements. For the most
Suppose you're designing an application (WebApp, Desktop, anything) and you need to define exception
I am designing an algorithm that works as follows: Suppose that there are N
I'm in a process of designing a multi-tier ASP.NET web application that is supposed
Suppose I have: public class foobar { public int lorem; public int ipsum; }
Suppose we have the following table data: ID parent stage submitted 1 1 1

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.