⬆️ ⬇️

Paradigms and Policies of Foundation Framework (Foundation Paradigms and Policies)

On the one hand, the translation of official documentation is not a very interesting thing, on the other - this translation cannot be found anywhere, the documentation itself is written in quite a lively language, and indeed, this is my personal blog. But maybe this note will be of interest to other programmers working on Macs.



The Foundation presents several paradigms and policies for Cocoa programming to ensure consistent and expected behavior of program objects in various 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 to release them when objects become unnecessary. The Garbage collection, introduced in Objective-C 2.0, automatically tracks and manages objects that your program no longer needs, freeing up memory in this way. The Foundation also still provides the traditional way to manage memory. It is based on a policy of ownership of objects, which stipulates that the objects are responsible for the release (release, releasing) of other objects that they created, copied, or explicitly took possession of (objects, retained). NSObject (class and protocol) defines methods for retaining and releasing objects. The authoring pool (defined in the NSAutoreleasePool class) implements a delayed release mechanism and provides an opportunity for the Cocoa program to have an agreed agreement to return objects for which the caller is not responsible. To learn more about garbage collection and memory management, see Object Retention and Disposal.

')

Mutable class types (Mutable class variants). The set of variables and container classes in the Foundation have mutable variants of immutable classes, and the mutable class is always the successor of the mutable. If you need to dynamically change an encapsulated variable or class member, you can create an instance of the class being modified. Since it is an inheritor of an immutable class, you can pass a mutable object to methods that require an immutable type. For more on mutable objects, see Object Mutability.



Class clusters. A cluster of classes 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 that are optimized for various types of stored information. Over time, a set of specific classes changed several times without disrupting the work of the programs. To learn more about clusters, see Class Clusters.



Notifications (Notifications). Notification is an important Cocoa programming pattern. It is based on the broadcast mechanism, which 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 recipient of the notification. There are several types of notifications: synchronous, asynchronous and distributed. The notification mechanism of the Foundation framework is implemented using the NSNotification, NSNotificationCenter, NSNotificationQueue, and NSDistributedNotificationCenter classes. To learn more about notifications, see Notifications.

Source: https://habr.com/ru/post/31689/



All Articles