Foundation Framwork (Foundation Paradigms and Policies)

Original author: Apple
  • Transfer
On the one hand, the translation of official documentation is not a very interesting thing, on the other hand, this translation is not to be found anywhere, the documentation itself is written in a fairly lively language, and, in fact, this is my personal blog. But maybe this note will be interesting to other programmers working on Macs.

Foundation introduces several Cocoa programming paradigms and policies to ensure consistent and expected behavior of program objects in different situations. These include:

Object retention and object disposal.Objective-C and Foundation provide Cocoa with two ways to ensure that objects exist when they are needed, and release them when objects become unnecessary. The Garbage collection, introduced in Objective-C 2.0, automatically monitors and manages objects that your program no longer needs, freeing up memory. Foundation also continues to provide a traditional way of managing memory. It is based on the policy of ownership of objects, which provides that objects are responsible for the release (release, releasing) of other objects that they created, copied, or explicitly took over (numbered, retained). NSObject (class and protocol) defines the methods of retaining and releasing objects. The authorization pool (defined in the NSAutoreleasePool class) implements a deferred release mechanism and allows the Cocoa program to have an agreed agreement on returning objects for which the calling method is not responsible. To learn more about the garbage collector and memory management, seeObject Retention and Disposal

Mutable class variants. Many variables and container classes in Foundation have mutable variants of immutable classes, and a mutable class is always the descendant of an immutable one. If you need to dynamically change an encapsulated variable or a member of a class, you can create an instance of the mutable class. Since it is the descendant of an immutable class, you can pass a mutable object to methods that require an immutable type. For more information on mutable objects, see Object Mutability

Class clusters.A class cluster is an abstract class and a set of private concrete classes for which the abstract class is an umbrella interface. Depending on the situation (and especially on the way you created the object), the object will have a suitable class that will be returned to you. NSString and NSMutableString, for example, act as intermediaries for objects of various private subclasses, optimized for various types of stored information. Over time, the set of specific classes has changed several times without disrupting the operation of programs. To learn more about clusters, see Class Clusters

Notifications.Notification is an important programming pattern in Cocoa. It is based on a broadcast mechanism that allows objects (called observers) to be aware of what another object is doing or to receive information about user or system events. The object generating the notification may not be aware of the existence or distinctive features of the notification recipient. There are several types of notifications: synchronous, asynchronous, and distributed. The notification framework mechanism is implemented using the classes NSNotification, NSNotificationCenter, NSNotificationQueue, and NSDistributedNotificationCenter. For more information about notifications, see Notifications.

Also popular now: