The professor provided a brief overview of sub-classing, method and property overrides, multiple initializers (using distinguishable paramater signatures). Protocols and generics were mentioned briefly.
Extensions
extension Double // built-in Swift type
{
func celsiusToFahrenheit() --> Double
{
return( self * 9 / 5 + 32.0 )
}
func fahrenheitToCelsius() --> Double
{
return( self - 32 * 5 / 9 )
}
}
⋮
anotherDouble = someDouble.celsiusToFahrenheit ( 0.0 ) // gets 32 ℉
Programming style
MVC design
Software should be designed according to the MVC paradigm, where
- M stands for model—contains implementation classes (public interface as well as private); persistent data of whatever type is stored here
- V represents view—i.e., user interface (UI), strictly
- C is controller—this manages the interaction between model and view components, which know nothing of each other.
This approach has two main benefits:
- it affords parallel development of aspects of a project
- it results in highly reusable objects.
Modular coding
Ideally, coding should be done in modular fashion, keeping two main principles in mind:
- maximize cohesion, that is, interaction of components within a module—things which do not or need not interact do not belong within the same module
- minimize coupling, the degree of interdependence of modules.
In support of this goal, one should aim for two categories of function:
- those which orchestrate activities
- those which implement them.
Nomenclature
In all cases, functions and variables should be named in such a fashion as to inherently document their purpose. To this end, somewhat longer naming is often to be preferred over obscure short forms.