Windows Phone 7 for iPhone Developers: Object-Oriented Programming
- Certainly not every good program is object-oriented, and not every object-oriented program is good.
- —Bjarne Stroustrup
Regardless of the type of application you plan to write, or the platform on which you plan to write it, you will need to utilize and understand some basic object-oriented principles and concepts.
Most developers are already familiar with concepts such as inheritance, contract-based (interface) programming, members, methods, encapsulation, and more. However, those concepts each have different implementations and even different terminology on different platforms. This chapter will help clear things up and show you how the core tenets of OOP are implemented in iOS and WP7.
Why OOP?
If you're reading this book, you probably do not need to be convinced that object-oriented programming is a good thing. However, as the chapter quote from Bjarne Stroustrup so eloquently puts it—not all OOP is a good thing. Like any tool, if used inappropriately, it can make a royal mess of any well-intentioned project.
We create classes as a way to group logically related data and behavior that's all geared toward performing a certain task. When these classes are written properly, they exemplify the benefits of OOP: increased reuse and the creation of testable, reliable, predictable applications that are easy to build, easy to maintain, and easy to change.
On mobile devices, we have classes that encapsulate information and behaviors for all kinds of things from reading GPS coordinates, to displaying text, to accepting input. Without a carefully architected suite of classes that abstract all the capabilities of a device, we would never be able to rapidly and reliably produce software for that device.
The same is true for the applications we build and the code we write. Without our own ability to create reusable classes, even the relatively small amount of code we write for mobile applications would be impossible to maintain and deliver applications on time and on budget.