I recalled some thoughts about in iOS from other backgrounds , including Java. Some things have changed due to ARC. In particular, memory management is no longer front-line and central. However, everything you did to simplify memory management (use accessors, use accessors, use accessors) is still equally true in ARC.
@Radu is perfectly correct that you should often keep class hierarchies fairly simple and shallow (as you read). Composition is often much better for Cocoa than extensive subclasses (this is probably true in Java, but it is common practice in ObjC). ObjC also has no concept of an abstract method or class, which makes some subclasses a bit uncomfortable. Instead of extracting common logic into base classes (especially abstract base classes), it is often better to extract them into a separate strategy object.
See the UITableView and its use of delegates and data sources. Look at things like NSAttributedString , which is HAS-A NSString , not IS-A. This is common and often keeps things cleaner. As with all large object hierarchies, always keep the LSP . I see that the ObjC design goes sideways when someone forgets that a square is not a rectangle . Again, this applies to all languages, but it is worth remembering during development.
Immutable objects (values) are a real victory whenever you can use them.
The other part that you quickly discover is that there are very few “protective decorations” such as “final” or “protected” (there is @protected , but this is not really useful in practice and is rarely used). People from the Java and C ++ backgrounds tend to worry about compilers complying with various access rules. ObjC has no protection against most protected compilers (you can always send any message you want for any object at runtime). You just use consistent naming conventions and don’t look at private methods. Programming discipline applied. In practice, this works very well in the vast majority of cases.
However, ObjC has many warnings, and you absolutely must eliminate all warnings. Most ObjC warnings are actually errors.
I deviated a little from the specific question about object hierarchies, but hopefully this is helpful.
source share