Tuesday, 26 July 2016

Object-Oriented Programming with Android Applications

Object-oriented programming  a big change in mobile application development and programming. An object-oriented program is, at its heart, designed to be modified. Using correctly written software, you can take advantage of features that are already built in, add new features of your own, and override features that don’t suit your needs.

For example, You have and employee with name and job title . Employee has many other attributes but now we are considering some basic:
class Employee {
  String name;
  String jobTitle;
}
Any other company has different types of employees. For example, In your company may have full-time and part-time employees. Every full-time employee has a yearly salary:
class FullTimeEmployee extends Employee {
  double salary;
}
The words extends Employee means the new class "FullTimeEmployee" has all the properties  of the "Employee class"
Like any Employee, a FullTimeEmployee has a name and a jobTitle. But a FullTimeEmployee also has a salary. 
For example part-time employee has no fixed yearly salary. Instead, every part-time employee has an hourly pay rate and a certain number of hours worked in a week:
class PartTimeEmployee extends Employee {
  double hourlyPay;
  int hoursWorked;
}
So by this a PartTimeEmployee has four characteristics: namejobTitle,hourlyPay, and number of hoursWorked.
Now for example you have to create a class for  executives. Every executive is a full-time employee. But in addition every executive will receive bonus  (even if the company goes belly-up and needs to be bailed out):
class Executive extends FullTimeEmployee {
  double bonus;
}
Java's extends keyword is very useful because, by extending a class, you inherit all the complex code that's already in the inherited class. The class you extend can be a class that you have (or another developer has) already written. One way or another, you're able to reuse existing code and to add ingredients to the existing code.
Now For example : The  Android wrote the Activity class, with its 4,000 lines of code. You get to use all those lines of code for free by simply typing extends Activity:
public class MainActivity extends Activity {
With these two words extends Activity, your new MainActivity class can do all the things that another Android activity can do : 

No comments:

Post a Comment