Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are asking for the 'proper way', as if in OOP there is a single correct answer.</p> <p>In reality there not one correct design. It is all relative to how you expect the code to be extended and repurposed in the future.</p> <p>If you really want to prepare yourself for every imaginable extension, then you'll end up with a ridiculously complicated design, and still not cover it all.</p> <p>In your example: Going from a touch-controlled spinner to something that's part of a 2D physics simulation... that's quite a long jump. Why would I even want to implement that with a common base class?</p> <ul> <li><p>If you just want a baseclass for 'something on the screen that can spin'... I'd say that's too generic. There isn't enough added value to justify a new class for that: UIView can already do that.</p></li> <li><p>If your original object was intended to get user input, then stick to the design pattern of the iOS and subclass UIControl.</p></li> <li><p>If you envision a physics simulation. Then you probably have a whole class structure that is independent of how it is shown on screen:</p></li> </ul> <p>A Rigid class to describe mechanical properties (shape, weight, ...) of each object (possibly a class tree. You can use a separate delegates for collision detection. ) A RigidState, describing position and velocity for a Rigid. A RigidSimulator, owning a set of Rigids and a RigidState for each rigid. A RigidViewController that can creates a UIView (probably an UIImageView) for a given Rigid and can adjust its size and position (given a RigidState). ... Something along those lines. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload