Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>here's what i use in the case of a explicit subclass structure:</p> <pre><code>@class MyObject; @interface MONBase : NSObject /* required override */ -(MyObject *)doSomething; /* ... */ @end @implementation MONBase /* ... */ -(MyObject*)doSomething { assert(0 &amp;&amp; "this override is required"); return nil; } @end </code></pre> <p><em>however</em>... protocols are often generally more useful in these and similar cases. the following exhibits one way to achieve this. it implements a protocol and inherits from the shared base -- use derived from the usage in the OP:</p> <pre><code>@class MyObject; @protocol MONProtocol /* required overrides: */ @required - (MyObject *)doSomething; /* optional overrides: */ @optional @end /* base, with shared implementation */ @interface MONBase : NSObject @end @implementation MONBase - (MyObject *)doSomething { /* as long as the sig matches, you won't need to declare it in the interface -- that may be a good thing. you may prefer *not* to implement this, if you favor a runtime exception */ assert(0 &amp;&amp; "this MONProtocol override is required"); return nil; } @end /* subclass of MONBase which extends by implementing MONProtocol */ @interface MONSub : MONBase &lt;MONProtocol&gt; { MyObject* theIvar; /* &lt;&lt; simplest case implementation */ } @end @implementation MONBase /* ... */ - (MyObject *)doSomething { return [[theIvar retain] autorelease]; } @end </code></pre> <p>protocols are nice because they provide many benefits of multiple inheritance, and provide very little dependencies.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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