The progress of abstraction
Assembly language is a small abstraction of the underlying machines.
Many so-called “imperative” languages that followed (such as FORTRAN, BASIC, and C) were abstractions of assembly language. 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,” which is the place where you’re implementing that solution, such as a computer) and the model of the problem that is actually being solved (in the “problem space,” pwhich is the place where the problem exists, such as a business). 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,” respectively). 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 may be 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 goes a step further by providing tools for the programmer to represent elements in the problem space.We refer to the elements in the problem space and their representations in the solution space as “objects.”
OOP allows you to describe the problem in terms of the problem, rather than in terms of the computer where the solution will run.
These characteristics represent a pure approach to object-oriented programming:
Everything is an object. Think of an object as a fancy variable; it stores data, but you can “make requests” to that object, asking it to perform operations on itself. 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.
A program is a bunch of objects telling each other what to do by sending messages.
Each object has its own memory made up of other objects. You can build complexity into a program while hiding it behind the simplicity of objects.
Every object has a type. Using the parlance, each object is an instance of a class, in which “class” is synonymous with “type.” The most important distinguishing characteristic of a class is “What messages can you send to it?”
All objects of a particular type can receive the same messages.
Booch offers an even more succinct description of an object: An object has state, behavior and identity.
An object has an interface
An object provides services
In a good object-oriented design, each object does one thing well, but doesn’t try to do too much.
The hidden implementation
It is helpful to break up the playing field into class creators and client programmers.
In any relationship it’s important to have boundaries that are respected by all parties involved.
So the first reason for access control is to keep client programmers’ hands off portions they shouldn’t touch.
The second reason for access control is to allow the library designer to change the internal workings of the class without worrying about how it will affect the client programmer.
Access specifiers:
public means the following element is available to everyone.
The
private keyword means that no one can access that element except you, the creator of the type, inside methods of that type.
The
protected keyword acts like private, with the exception that an inheriting class has access to protected members, but not private members. 包内所有类可见,包外有继承关系的子类可见
Java also has a “
default” access. It is usually called
package access because classes can access the members of other classes in the same package (library component), but outside of the package those same members appear to be private.
Reusing the implementation
Code reuse is one of the greatest advantages that object-oriented programming languages provide.
Because you are composing a new class from existing classes, this concept is called composition (if the composition happens dynamically, it’s usually called aggregation). Composition is often referred to as a “has-a” relationship, as in “A car has an engine.”
Composition comes with a great deal of flexibility. The member objects of your new class are typically private, making them inaccessible to the client programmers who are using the class. This allows you to change those members without disturbing existing client code. You can also change the member objects at run time, to dynamically change the behavior of your program. Inheritance, which is described next, does not have this flexibility since the compiler must place compile-time restrictions on classes created with inheritance.
Inheritance
- 大小: 16.4 KB
分享到:
相关推荐
在IT领域,面向对象编程(Object-Oriented Programming,OOP)是一种广泛采用的软件开发范式,它基于“对象”这一核心概念。本章节深入探讨了对象、抽象数据类型(Abstract Data Types,ADTs)、信息隐藏...
1: Introduction to Objects 2: Making & Using Objects 3: The C in C++ 4: Data Abstraction 5: Hiding the Implementation 6: Initialization & Cleanup 7: Function Overloading & Default Arguments 8: ...
ChaptEr 1 an introduction to Programming 1 ChaptEr 2 Beginning the Problem-Solving Process 23 ChaptEr 3 Variables and Constants 51 ChaptEr 4 Completing the Problem-Solving Process 75 ChaptEr 5 The ...
Chapter 11, Introduction to Objects - 3 - Intermediate Perl Work with classes, method calls, inheritance, and overriding. Chapter 12, Objects with Data Add per-instance data, including ...
Introduction to Objects Object-relational features enhance the capabilities of the database: - **Object Types**: Defining object types to represent complex data structures. - **Object Tables**: ...
Introduction to Computer Science Using Python: A Computational Problem-Solving Focus introduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-...
### Introduction to Python Programming Python is a high-level, interpreted programming language that is widely used for various applications, including web development, data analysis, artificial ...
3 edition (October 30, 2004) <br>Applying UML and Patterns is the world\'s #1 business and college introduction to \"thinking in objects\"and using that insight in real-world object-oriented ...
InfiniBand features Glossary Get familiar with IB HW/SW entities Get familiar with data path operations Get familiar with IB SW objects
A NEW INTRODUCTION TO MODAL LOGIC Preface ix Part One: Basic Modal Propositional Logic 1 The Basic Notions 3 The language of PC C) Interpretation D) Further operators F) Interpretation of A , D...
While most developers today use object-oriented languages, the full power of objects is available only to those with a deep understanding of the object paradigm. How to Use Objects will help you gain ...
ncRef.rebind(ncRef.to_name(name), hello); System.out.println("Server ready"); orb.run(); } } ``` ### 部署考虑 在实际应用中,部署分布式系统需要考虑以下几个方面: - **安全性**:确保远程对象访问...
Chapter 2 - Brief Introduction to Unity IDE Chapter 3 - Game Objects and Components Chapter 4 - Game Rules and Mechanics Chapter 5 - Creating the User Interface Chapter 6 - Creating Battleship Chapter...
Introduction to Visual Computing: Core Concepts in Computer Vision, Graphics, and Image Processing covers the fundamental concepts of visual computing. Whereas past books have treated these concepts ...
Introduction to Computer Science Using Python: A Computational Problem-Solving Focusintroduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-...
第2章“Introduction to Objects”(面向对象导论)深入探讨了面向对象编程的概念,如类和对象的关系、接口和实现的分离、继承、多态和抽象类等。第3章“Hello, Objects”(你好,对象)介绍了对象的创建和引用,...
《对象的引入》(Introduction To Objects) 1.1 抽象的进步 所有编程语言都提供抽象机制,这使得我们能够解决复杂的问题。抽象的程度和质量直接影响到你能处理问题的能力。“种类”指的是“你在抽象什么?”汇编...