Professional Documents
Culture Documents
Applications
Chapter 3: Best Practices for
Small Device Programming
Encapsulation
Inheritance
Automatic access to information in
superclass
Allows you to define how your class
differs from its superclass
Subclassing is the process of inheriting
from a superclass
C#, Java, and Objective-C all have a
single-inheritance model
Dynamic method invocation
Programming with Mobile Applications
Inheritance (continued)
Polymorphism
The ability to substitute a subclass
for a superclass
Interfaces, protocols
define behavior of objects
provide for multiple inheritance
Design Patterns
Best practices for structuring an
application
Model-View-Controller (MVC)
Delegation
MVC
Separation of programming concerns
into separate tiers
Model the data tier
View the interface presented to the
user
Controller brokers requests
between the model and the view
Figure 3-4 The Model-View-Controller model
Programming with Mobile Applications
10
Optimization
Making programs run faster or on
less memory
Smartphones = constrained
resources
11
12
13
Memory Management
C# and Java include automatic garbage
collection
Reference Counting
Memory Leaks
Objective-C Memory Management Rules
If the new, alloc, or copy methods are used to
create an object, youre responsible for releasing it.
If another mechanism is used to get a reference to
an object, assume it has been auto-released.
If you retain an object, you must eventually release
it.
Programming with Mobile Applications
14
Memory Management
(continued)
Create objects only when needed.
Create the fewest number of objects
possible.
Close everything you open.
Be careful with collections of objects.
Restrict the scope of objects when
possible.
Programming with Mobile Applications
15