I think that keeping archiving and unarchiving functionality in separate classes is the result of applying the Single Responsibility Principle, which says that a class has to have a single, narrow, responsibility, which should be fully encapsulated inside that class. Indeed, when you create an instance of NSCoder
's subclass, you do that either to archive a group of objects, or to unarchive data into a group of objects, but not both.
This design is not ideal, because now you have several pairs of classes (i.e. NSArchiver
/NSUnarchiver
and NSKeyedArchiver
/NSKeyedUnarchiver
) linked by communicational cohesion, while a single-class design would have lead to this data dependency being fully encapsulated. This is a tradeoff on which the designers of the Cocoa library could have gone either way. It appears that they picked single responsibility principle, at the price of introducing a data format dependency.