Java Reference
In-Depth Information
As your employee program evolves, you will certainly find yourself adding
and changing procedures so that everything works successfully. For example,
as you start writing the computePay() procedure, you might realize that there
are two different types of employees (at least in terms of how they get paid):
hourly employees and salaried employees. In this situation, you might decide
to write two computePay() procedures, one for hourly employees and a differ-
ent one for salaried employees.
Writing a procedure to solve a specific task is a fundamental programming
concept used in both procedural languages and in object-oriented program-
ming. As you design and write Java programs, procedures will be an essential
element for solving the problem at hand.
In Java, procedures are referred to as methods. Methods in Java appear
within a class. Procedures in a procedural language typically appear at a
global level so that they can be invoked from anywhere.
Object-Oriented Programming
Object-oriented programming (OOP) originated from research done by Xerox's
Palo Alto Research Center (PARC) in the 1970s. OOP takes an entirely different
approach to developing computer applications. Instead of designing a pro-
gram around the tasks that are to be solved, a program is designed around the
objects in the problem domain.
You can think of procedural programming as writing a procedure for the
verbs in the problem domain, such as paying an employee or computing
taxes. You can think of object-oriented programming as writing a class
for each of the nouns in the problem domain. Granted, this may be
oversimplifying OOP, but I want you to conceptually understand this
important difference between OOP and procedural programming.
Let's take another look at the example in which a program is to be written to
pay employees of a company on a weekly basis. Instead of approaching this
problem from the point of view of all the little tasks that need to be performed,
such as computing an employee's pay and taxes, you begin by determining the
objects in the problem domain.
An object is any person, thing, or entity that appears in the problem domain.
In our example, we want to pay employees, so the employees are objects. The
employees work for a company, so the company is another object. After fur-
ther analysis, you might decide that the payroll department is an object. After
you start writing the program, other objects will be discovered that were not
apparent in the initial design.
Search WWH ::




Custom Search