-
Begin Java
{ PA GE } Thinking in Java www.BruceEckel.com
significant library of well-designed, easy to use objects. Thus, the primary job of most programmers is to
use existing objects to solve their application problems. The goal of this chapter is to show you what
object-oriented programming is and how simple it can be.
This chapter will introduce many of the ideas of Java and object-oriented programming on a conceptual
level, but keep in mind that you’re not expected to be able to write full-fledged Java programs after reading
this chapter. All the detailed descriptions and examples will follow throughout the course of this book.
The progress of abstraction
All programming languages provide abstractions. It can be argued that the complexity of the problems you
can solve is directly related to the kind and quality of abstraction. By “kind” I mean: what is it that you are
abstracting? Assembly language is a small abstraction of the underlying machine. Many so-called
“imperative” languages that followed (such as FORTRAN, BASIC, and C) were abstractions of assembly
language. These languages are big improvements over assembly language, but their primary abstraction
still requires you to think in terms of the structure of the computer rather than the structure of the problem
you are trying to solve. The programmer must establish the association between the machine model (in the
“solution space”) and the model of the problem that is actually being solved (in the “problem space”). The
effort required to perform this mapping, and the fact that it is extrinsic to the programming language,
produces programs that are difficult to write and expensive to maintain, and as a side effect created the
entire “programming methods” industry.
The alternative to modeling the machine is to model the problem you’re trying to solve. Early languages
such as LISP and APL chose particular views of the world (“all problems are ultimately lists” or “all
problems are algorithmic”). PROLOG casts all problems into chains of decisions. Languages have been
created for constraint-based programming and for programming exclusively by manipulating graphical
symbols. (The latter proved to be too restrictive.) Each of these approaches is a good solution to the
particular class of problem they’re designed to solve, but when you step outside of that domain they
become awkward.
The object-oriented approach takes a step farther by providing tools for the programmer to represent
elements in the problem space. This representation is general enough that the programmer is not
constrained to any particular type of problem. We refer to the elements in the problem space and their
representations in the solution space as “objects.” (Of course, you will also need other objects that don’t
have problem-space analogs.) The idea is that the program is allowed to adapt itself to the lingo of the
problem by adding new types of objects, so when you read the code describing the solution, you’re reading
words that also express the problem. This is a more flexible and powerful language abstraction than what
we’ve had before. Thus OOP allows you to describe the problem in terms of the problem, rather than in the
terms of the solution. There’s still a connection back to the computer, though. Each object looks quite a bit
like a little computer; it has a state, and it has operations you can ask it to perform. However, this doesn’t
seem like such a bad analogy to objects in the real world; they all have characteristics and behaviors.
Alan Kay summarized five basic characteristics of Smalltalk, the first successful object-oriented language
and one of the languages upon which Java is based. These characteristics represent a pure approach to
object-oriented programming:
1. Everything is an object. Think of an object as a fancy variable; it stores data, but you can also ask it to
perform operations on itself by making requests. In theory, you can take any conceptual component in the
problem you’re trying to solve (dogs, buildings, services, etc.) and represent it as an object in your program.
-
this guy were spamming... MOD! handle this guy :lol: :lol:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks