For this entry I wanted to introduce the coding approach that will be used for the three native (on the Android and iOS operating systems) applications I'll be developing.
In later posts, I'll discuss the three particular development platforms I'll be using (Flash CS 5.5, Xcode and Eclipse). While each of these platforms and their target devices differ in many ways, the core coding approach is the same for all three: Objective-C.
As the name suggests Object -Oriented coding focuses on classes (or groups) of objects. The most common example used when teaching this coding approach is to think of automobiles as a class of objects.
All automobiles have certain characteristics (or parameters) in common. Here are some examples: every car has an engine, a transmission, a make and a model. These characteristics vary from one car to another. Even the same model of a car can vary for each individual car that exists. Is the exterior blue, does it have an automatic transmission, leather or cloth seats, etc.
My personal car would be a specific instance of an automobile class object: Toyota, front-wheel drive, blue exterior, standard transmission, 2007, etc.
In addition to an object having parameters or characteristics, an object or class of objects will have certain actions that it can perform or have performed on it. Sticking with the automobile analogy some examples would be: accelerate (pressing the gas pedal), reading the gas level gauge, turning on the headlights, etc.
Some of the actions, which are often called methods, may be common to all cars. Some may be unique to a specific type of car. For example, an SUV may have an action to enable four-wheel or all- wheel drive. Many cars would not have that same action since they are only two-wheel drive.
So how do we handle these differences? Do we make another entire class automobiles from scratch? We could but the better approach is to make a sub-class of automobiles that have all the characteristics and methods of our original automobile class but can also have some unique characteristics or methods of their own. This is a concept called inheritance. Any sub-class (also called a child class) inherits all the characteristics and methods of its super-class (or parent class).
Why is this helpful? Well if we find a problem with one of the automobile class methods, we can fix it once and every automobile and sub-class of automobile, get the fix at the same time. Wouldn't the real auto manufacturers kill for this benefit. Imagine all the money and headaches saved without having full-blown recalls to fix one car at a time!
Inheritance makes code easier to maintain and more re-usable. Both are extremely helpful when coding a lot of different - but similar - projects.
So for this project we can make an Electronic Component class with characteristics like component value and tolerance. Then we can have sub-classes such as the Resistor sub-class and the Capacitor sub-class. Each sub-class can have it's own unique characteristics and methods as needed.
Another example is an Electrical Source class with sub-classes such as DC Voltage source, AC Signal Supply, etc.
Therefore one of the first steps for our project is to define this class infrastructure so that we can leverage benefits like inheritance, code re-usability, and easy expansion and maintenance.
Hopefully this sets the stage for the coding backend of the projects. Later posts will elaborate on the classes that are being developed and how they are used.
Comments and questions are welcome!
No comments:
Post a Comment