COSC346
Facade
A façade is like a proxy, but the actual work is being done by a collection of other objects. Google is an example of a façade, which forwards requests to other workers.
Garbage Collection
A garbage collector scans through memory, and if it finds unused objects, it marks them for de-allocation. This method can recognize and deal with retain cycles. Both Coca and Java use an entire separate process to handle garbage collection. Slowest, safest, easy to use.
Singleton
A singleton class allows only one instance of the class to exist.
Generics (Parametric Polymorphism)
A way to write a method without specifying the parameters type, instead using a "generic" type. e.g The [NSArray addObject:] takes a parameter of a generic type, which allows it to accept almost any object type. Both Objective-C and Swift have generics.
Interchangeability
Ability to change inner workings of an object without affect its interface and the code depending upon it
Windows in Cocoa
All NSWindows. Associated with NIB file
Deferred Choices - UI Design
Allow the user to answer only the bare minimum number of questions at any given time
Safe Exploration - UI Design
Allow the user to explore without getting lost or in trouble. Examples include: Undo/redo for document changes Back button, escape for navigation Easily unsubscribe from services on a webpage Trash can in the operating system
Alternative Views
Alternative views can be combined with other patterns to allow additional flexibility in viewing information. E.g. Word web browsers (combo of heaps of views)
Escape Hatch
Always provide a way to back out of any action if you can
Adapter
An adapter provides an interface between two incompatible objects. The most common example is the middleware between the client and a database.
MVC in Cocoa
AppKit is the view in MVC. Has responders and View shit like buttons AppKit is the Controller. Has a NSController that controls shit and the code logic that connects the View and Model components Coredata is Model
Structures in Swift e.g. INT
Can have properties/methods/subscripts/initialisers/Be extends/conform to protocols <- Same as classes Structures cannot inherit/type cast/Deinitialisers /reference count
Animated Transitions
Capture attention to show what to do next or where to find something later e.g. minimize animation
What actions should be undoable?
Changes to documents etc
Downcasting
Changing down to child class -> Very bad practice.
Upcasting
Changing type label of an object to that of its parent
Methods
Class specific functions that define what the object does and how it does it
Benefits of Inheritance
Code reusability - no need to implement methods inherited from the parent. Interface consistency - easy to conform to generic requirements for an interface while implementing only few methods. Code portability - lower level routines (superclasses at the top of the tree) can be used in different projects.
Cohesion
Cohesion is how well the object internals go together. It refers to the relationship between the internal elements of the class. An example is data cohesion which is when many elements serve to implement one data abstraction, or coincidental cohesion where elements of a class a grouped for no apparent reason. You want to increase this
Colour-Coded Sections
Colour code sections of an application or webpage according to user's location
Habituation - UI Design
Consistency across applications and within application
NSController/Controllers
Controllers offer the following advantages: • Less code (if using bindings) • Takes care of selection/editing for you (e.g., text fields in tables, aborted input, committing edits to model, etc.) • Controllers are compatible with other advanced features, such as undo/redo and Core Data
Delegation
Delegate is another form of callbacks. A delegate is an object implementing a number of callback methods. Instead of registering each callback method, you register the delegate. After knowing the delegates reference, the caller can invoke variable methods on the delegate object. Protocols are very useful for delegation because you can specify the methods to be implemented by the delegate.
Changes in Midstream - UI Design
Don't lock users into interactions they have to finish, unless you absolutely have to. Support reentrance (stop and continue later).
Views in Cocoa (NOT MVC)
Each NSWIndow has NSView object inside it. Put buttons inside of this etc
Encapsulation
Encapsulation is restricting access to the inner state of an object. This usually involves only allowing users of the class to access its internal variables through accessor methods. By having these methods in place between the user and your variables you can control what the values are being set to, and provide information of the change to other parts of the class if need be. An example of encapsulation would be a temperature class. You can set the temperature with C or F, and get the temperature in C or F. It doesn't matter what your stored it as, or which you want to get out, the class can do the conversion for you.
Modal Panel
Error window, no one reads it
NSEvent
Events are passed to handling methods as NSEvent objects
Extras on Demand
Hide complexity when its not needed
Coupling
How much different components of a system, such as objects in a program, depend on each other. The relationship between classes. Examples of coupling include internal data coupling when there is direct access to an instance variable of another class, or global data coupling when there is a dependency on global variables. You want to minimise this
Prospective Memory - UI Design
I'm putting this here to remind myself to deal with it later. e.g. calendars/list software
Support Keyboard-only Operation - UI Design
Implement keyboard alternative to most application functionality
Clear Entry Points
In applications designed for first-time, infrequent users, present only a few entry points. E.g. Google
Dynamic Typing
In dynamic typing the data type is derived from its value. Type checking is all done at runtime. This allows you to make generic code which works with any type. Potential bugs might lurk in the code, and not manifest itself until certain runtime conditions are met. Dynamic typing is more flexible, but you must do more error-checking yourself.
Static Typing
In static typing the data type is derived from the variable definition. This means that the compiler is able to check for type mismatches so can spot potential bugs. In static typing the type must always be specified. You cannot compile code that has a type mismatch. Static typing is more readable and allows the compiler to do error-checking.
Inheritance
Inheritance is the creation of a subclass from a previously existing class. It allows you to reuse code, because you get all of the methods available to the parent which you can then add your own functionality to. When inheriting from a class you are able to add new methods, or override any existing methods. Any method call on a the subclass which it cannot handle will be passed to its superclass.
Interface Idioms
Interface idioms are UI styles that have become accepted for certain tasks
Mutable Object
Internal state can be modified at any poiny
Immutable object
Internal state does not change after initialisation
NSControl
Is an abstract class that contains a reference to a target and action, which can be triggered after an event
Object
Is an instance of a class
Hub and Spoke
Isolate sections of application into mini-applications, each one click away from central hub. E.g. iOS 8 app design
Why is MVC good ?
It decouples the view and the model layers (separates storage and display). This helps to make the model and view objects reusable. GUIs tend to change often, whereas underlying data does not. So uses MVC ensures that you only make changes to one layer. Ensures objects remain highly cohesive. E.g. view objects not worried about how data is stored.
Application Delegate
It serves the NSApplication object. It must subscribe to the NSApplicationDelegate protocol, which contains optional methods for: launching, terminating, managing the active status, and hiding your application.
Key Value Coding
KVC allows us to get and set instance variables using key strings. To get a variable use valueForKey: to set a variable use setValue:forKey:. The key string is the same name as the instance variable. KVC is implemented at the NSObject level. It works by calling key-value compliant setters and getters. So for setters it would call -(void)set<Key>, and for getters it would call -(id)<Key>. Key-value coding automatically wraps non-objects as NSNumber or NSValue. KVC enables application scripting, underlies variable binding to GUI elements, and can help you simplify your code. Through KVC you can bind GUI elements directly to values in the model. This helps to simplify a lot of the controller glue code.
Navigation rules
Keep navigation distance short: the 80% most used features should be at most one click away Navigational controls often location sensitive: users expect back button in the upper left, the OK button on the lower right, etc. • Always provide back, escape or cancel navigation paths
Key paths
Key paths can be used to access instance variables indirectly e.g. let model = selectedPerson.valueForKeyPath("spouse.scooter.modelName") as! NSObject
Key-Value Observing
Key-value observing is a framework for setting up notifications for when a variable changes. You can register an observer's interest in an instance variable, so that it will be notified when it changes. The observer must implement the observeForKeyPath method, so that it can has a place for the notifications to be sent to allowing them to be handled correctly. KVO works on the NSObject level. An important thing to note is that KVO will only work if the variable changes using the accessor. This includes using key-value binding. Notifications can also be produced manually using willChangeValueForKey: and didChangeValueForKey:. It is important to note that KVO notifications are not NSNotifications, and that not all classes allow KVO because the class must support the informal NSKeyValueCoding protocol.
When to NOT inheritance
Limitation - subclass restricts behaviour of the parent class. Generalisation - subclass modifies behaviour of the parent.
Pyramid
Link pages with back/next/up: form pyramid
Instances
Many objects can be created from a given class, each instance has its own state.
MVC
Model - Information Storage View - Interface that allows user to interact with info Controller - Coordinates interactions between view and model.
Redo/Undo
NSUndoManager does this in swift. Instance of this has two stacks, for redo and undo.
NSWindowController
NSWindowController object contains methods for loading and closing of the associated window To create a new window, you allocate a new instance of NSWindowController (or its subclass) and associate it with a NIB file Window method of NSWindowController returns reference to the NSWindow object associated with the controller
How does NSUndoManager Work?
Next the user invokes 'undo' • Message on the top of the undo stack gets executed • The opposite message goes onto the redo stack Next the user invokes 'undo' again • Message on top of undo stack gets executed • The opposite message goes onto the redo stack • If the user invokes 'redo', opposite messages go from the 'redo' to the 'undo' stack
Spatial Memory - UI Design
Not moving elements around, i.e. Back button in the upper left
Breadcrumbs
On each page in a hierarchy, show a map of parent pages. E.g. the windows 7/8/10 bar thing showing the file path you are in
One-Window Drilldown
One-window drilldown shows one window of information at a time. Like the home screen of an iphone/ OX S system perferences
Canvas + Palette
Photoshop UI design
Polymorphism
Polymorphism refers to the ability of different class objects to respond to the same methods. The message sender doesn't care what form the receiver takes as long as they can handle the message it wants to send. These methods may operate in different ways but provide similar behaviour. This is most often used to provide similar functionality for different objects. The internal behaviour may be different, but the external interface is the same. A good example is the description method (Java toString), which every class has.
Proxy
Proxies are similar to an adaptor, but it hides more details. The proxy works as a standin for another (sometimes remote) object. The proxy pattern is used for the first responder object in a user interface.
Retain Cycles
Retain cycle occurs when objects references each other. A collection of objects can reference each other in a cycle, preventing any of them from being released. e.g. A needs B, B needs C and C needs A, none will release another, even though the running program has long forgotten about A, B and C. Typically occur when child references parents. In this situation, the retain count will never go to zero on these objects and they will never get deallocated, even if they are not being used. Use WEAK VAR in swift to get rid of this.
Polymorphism - Overloading
Same method (or function name) - which performs different things depending on the parameters it is given (whether it be more parameters, or parameters of different types). Constructor overloading is the most common form of this. Neither Swift or Objective-C allow function or method overloading :( Swift has "convenience constructors" which are overloading constructors.
What actions shouldn't be undoable
Selections, changing modes (e.g. tool types, colours) Changes to interface (e.g. font size, window size, preferences)
Sequence Diagrams
Sequence Diagrams illustrate how objects interact (via calls) to fulfill tasks.
How to set up controllers
Set Controller's Content Connect Controller to view
Stack
Short term, used for arguments and local variables within functions and methods. Cleared automatically
Sequence Map
Show where user is. E.g. navigation bar on side of slideshow
NSApplication
Singleton class that manages lifecycle of an application. Handles loading of GUI and runs main event loop
When to use Inheritance
Specialisation - subclass is a more specialised version of its parent e.g. every square is a rectangle, but not every rectangle is a square. Specification - subclass implements behaviour described, but not implemented by its parent. Extension - subclass provides new behaviour and capabilities.
Incremental Construction - UI Design
The ability to continually make small changes, i.e. not limited to few large changes.
Automatic Reference counting (ARC)
The calls to retain/release are inserted into appropriate positions by compiler.
Command
The command pattern encapsulates a request as an object. Then you can log requests, put them in a queue, undo/redo operations.
Iterator
The iterator pattern allows us to step through collections of objects. E.g. NSEnumerator
Event Loop
The main event loop waits for events to come from the OS and dispatches them to the appropriate handlers. The autorelease pool is drained after each iteration through the event loop. When the application terminates, all of your objects are destroyed. It is possible to get a reference to the main loop running inside the NSApplication class. This is useful for adding timers and communication ports to it.
Mediator
The mediator design pattern defines how a set of objects interact. It promotes loose coupling of objects. The NSController class in the Application Kit Framework follows the mediator pattern. This is important for GUIs in OSX.
Observer
The observer pattern defines a one-to-many dependency between objects. NSNotification supports the observer pattern.
Software Factory
The software factory pattern describes the ability of a class to make multiple objects. E.g. NSObject
Two-Panel Selector
The two-panel selector is a commonly used method to list objects and categories. Used to show data and context of that data e.g. email with list of shit on the side
Destructors
These clean up all the memory which the object has allocated . Then deallocates the object itself.
Composition
This is when a class includes another class as an instance variable. Composition is different to inheritance because you are including the other class as an instance variable rather than making yourself a subclass of it. The best way to define the difference is whether or not the class has a "IS-A" or "HAS-A" relationship. A car HAS-A wheel, a car IS-A vehicle.
Serialisation
This is when you convert an object into something which can be stored onto disk. An example would be storing an object's variables in json so that they can be read back into the object later.
Chain of Responsibility
This pattern allows more than one object to respond to a message. In Objective-C it is used to select methods at runtime. Within the class hierarchy the message is passed up toward the root until it is handled. If no one responds to the message, then an exception will be thrown.
Instant Gratification - UI Design
Try to predict things the user wants to do, and make it easy to do them.
Preferences in Cocoa (LOOK MORE INTO THIS)
Use NSUserDefaults. For communicating new preference settings to other parts of the application, we use notifications
Global Navigation
Use the same small section of every window to provide consistent navigation controls. E.g. shit on the top of web broswers
Annotated Scrollbar
Use the scrollbar to provide extra information as the user moves through a document
Heaps
Used for objects and is more persistent. Not obvious when its cleared in Swift
Satisficing - UI Design
Users will accept good enough if best means more time and effort.
Cost of inheritance
Weakens encapsulation Slower Execution speed Bigger memory usage
Abstraction
What an object does is more important than how it does it. The inner workings of the object have been abstracted away, leaving an easy to use interface. Abstraction is important in object oriented programming because it is what reduces the amount of prerequisite knowledge you need before you can start using a class.
Introspection
When using dynamic binding/typing you will sometimes get to a point that you need to ask an object about itself. By asking an object if it has a method before you attempt to call it you can reduce your chance of getting runtime errors. You can also make methods which can take different types and do different things depending on what was passed in. For example if you had a fraction class you could let it take regular NSNumbers, or your fraction class and still allow it to add either of them to your current fraction.
Wizards
Wizards provide restricted paths through potentially complicated, generally uninteresting processes. E.g. help
XML and NIB
XML - Just like android, description of components. NIB is compiled version of this.
NSResponder
is an abstract class that dispatches received NSEvents to methods corresponding to various mouse and keyboard events
Streamlined Repetition - UI Design
• Automate repetitive tasks, examples include • Find and Replace dialogs
NSUndoManager
1. Decide what should be undo-able 2. Implement an "inverse" message for every message that causes an undo-able action 3. Register your messages with the NSUndoManager
Callback
A callback is an argument passed to a function/method that is a reference to executable code. The function/method will then execute that code when it deems necessary. Callbacks can be thought of as a plugin which extends the functionality of the caller object.
CRC-Cards
A class Class Responsibility Collaboration card is a physical card that you write a basic class plan on.
Class
A class is a specification of how the object is to be built
Composite
A composite object includes other objects as instance variables - creating a hierarchy of objects. This is often used in graphical user interfaces.
Contructors
A constructor is a special method of a class or structure in object-oriented programming that initialises an object of that type. A constructor is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values. This is done in Swift with the init