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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:18:24+00:00 2026-06-01T04:18:24+00:00

I am making a drawing app for iOS and I have the following classes:

  • 0

I am making a drawing app for iOS and I have the following classes:

  • CanvasViewController holds a CanvasView and allows you to select a Brush for use in drawing
  • CanvasView is a UIView that contains a background color and an array of Stroke that are rendered by wiring up touches events and drawRect
  • Stroke is an NSObject that contains a UIBezierPath *path and a Brush
  • Brush contains an int brushType that is defined by a typedef and can be things like BrushTypeSolid, BrushTypeSpray, BrushTypePattern

Initially I thought about how I would handle drawing different brushType in my drawRect and it would be something like the following:

in drawrect

CGContextRef context = UIGraphicsGetCurrentContext();

UIGraphicsBeginImageContext(self.frame.size);

if ([squigglesArray count] > 0)  {

    for (WDSquiggle *squiggle in squigglesArray) {
        [self drawSquiggle:squiggle inContext:context];
    }
}

[self drawSquiggle:currentSquiggle inContext:context];

UIGraphicsEndImageContext();

in drawSquiggle

switch (squiggle.brushType): {
    case BrushTypeSolid:
         //solid brush stuff
         break;
    case BrushTypeX:
         //x stuff
         break;
}

However, now the drawing logic is all handled in a way that strongly ties the CanvasView and the BrushType together.

Is there an elegant way to encapsulate drawing logic in the BrushType or the Squiggle so that I could do something like:

[squiggle drawInRect:myRect]

or

[squiggle drawInView:myView]

Or, is this a stupid goal to have / I do not understand encapsulation?

  • 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-01T04:18:25+00:00Added an answer on June 1, 2026 at 4:18 am

    You could turn BrushType into a class with subclasses for each specific implementation and move the related logic inside drawSquiggle to it. drawSquiggle will simply call:

    [squiggle.brushType draw......]
    

    (you can certainly find the best name and parameters for this method)

    This is a refactoring called “replace conditional with polymorphism”.

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

Sidebar

Related Questions

I am making a drawing app and I want to increment my brush size
I'm making a simple drawing app on Android. I'm using the FingerPaint.java provided with
I'm making a drawing app. In the centre of the screen, I want the
I am playing around with a little drawing app I am making and was
I'm making a vector drawing application. I use this algorithm to generate outlines. This
I'm currently making an OpenGL ES 2.0 drawing app for the iPad and I
i am making a drawing with finger app. I want to set a start
I've got this strange bug in my app. I'm making a subview and drawing
So I'm making a drawing app that uses flash. I want to be able
I have been making paint application and i have implemented successfully drawing with paint

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.