oop的基本思想
OOP的许多原始思想都来之于Simula语言,并在Smalltalk语言的完善和标准化过程中得到更多的扩展和对以前的思想的重新注解。可以说OO思想和OOPL几乎是同步发展相互促进的。与函数式程序设计(functional-programming)和逻辑式程序设计(logic-programming)所代表的接近于机器的实际计算模型所不同的是,OOP几乎没有引入精确的数学描叙,而是倾向于建立一个对象模型,它能够近似的反映应用领域内的实体之间的关系,其本质是更接近于一种人类认知事物所采用的哲学观的计算模型。由此,导致了一个自然的话题,那就是OOP到底是什么?[D&T 1988][B.S 1991] .。在OOP中,对象作为计算主体,拥有自己的名称,状态以及接受外界消息的接口。在对象模型中,产生新对象,旧对象销毁,发送消息,响应消息就构成OOP计算模型的根本。
对象的产生有两种基本方式。一种是以原型(prototype)对象为基础产生新的对象。一种是以类(class)为基础产生新对象。原型的概念已经在认知心理学中被用来解释概念学习的递增特性,原型模型本身就是企图通过提供一个有代表性的对象为基础来产生各种新的对象,并由此继续产生更符合实际应用的对象。而原型-委托也是OOP中的对象抽象,代码共享机制中的一种。一个类提供了一个或者多个对象的通用性描叙。从形式化的观点看,类与类型有关,因此一个类相当于是从该类中产生的实例的集合。而这样的观点也会带来一些矛盾,比较典型的就是在继承体系下,子集(子类)对象和父集(父类)对象之间的行为相融性可能很难达到,这也就是OOP中常被引用的---子类型(subtype)不等于子类(subclass)[Budd 2002]。而在一种所有皆对象的世界观背景下,在类模型基础上还诞生出了一种拥有元类(metaclass)的新对象模型。即类本身也是一种其他类的对象。以上三种根本不同的观点各自定义了三种基于类(class-based),基于原型(prototype-based)和基于元类(metaclass-based)的对象模型。而这三种对象模型也就导致了许多不同的程序设计语言(如果我们暂时把静态与动态的差别放在一边)。是的,我们经常接触的C++,Java都是使用基于类的对象模型,但除此之外还有很多我们所没有接触的OOPL采用了完全不一样的对象模型,他们是在用另外一种观点诠释OOP的内涵。
急用,高分相送。
Many of the basic ideas of object-oriented programming come from the Simula language, and were further expanded and redefined during the completion and standardization of Smalltalk.
可以说OO思想和OOPL几乎是同步发展相互促进的。
It can be said that object-oriented concepts and object-oriented programming languages were developed at the same time, reinforcing each other.
与函数式程序设计(functional-programming)和逻辑式程序设计(logic- programming)所代表的接近于机器的实际计算模型所不同的是,OOP几乎没有引入精确的数学描叙,而是倾向于建立一个对象模型,它能够近似的反映应用领域内的实体之间的关系,其本质是更接近于一种人类认知事物所采用的哲学观的计算模型。
Different from the machine-like computational models of functional-programming and logic-programming, object-oriented programming almost did not introduce any precise mathematical description; instead, it leaned towards building an object model, which approximates the relationship between instances in the application fields. Its nature is closer to a computational model that is based on the same philosophy by which humans learn about the world.
由此,导致了一个自然的话题,那就是OOP到底是什么? [D&T 1988][B.S 1991] .。
Therefore it is natural to ask, what exactly is object-oriented programming?
在OOP中,对象作为计算主体,拥有自己的名称,状态以及接受外界消息的接口。
In OOP (以下就不扩展了,打字很累的), objects are the main subjects of computation; they have their own names, states, and also interfaces that are used to receive outside information.
在对象模型中,产生新对象,旧对象销毁,发送消息,响应消息就构成 OOP计算模型的根本。
In the object model, creating a new object, destroying the old object, sending messages, and replying to messages constitute the basis of the OOP computational model.
对象的产生有两种基本方式。
Objects can be created in two ways.
一种是以原型(prototype)对象为基础产生新的对象。
One is to create new objects based on prototypes.
一种是以类(class)为基础产生新对象。
The other is to create new objects based on class.
原型的概念已经在认知心理学中被用来解释概念学习的递增特性,原型模型本身就是企图通过提供一个有代表性的对象为基础来产生各种新的对象,并由此继续产生更符合实际应用的对象。
The concept of prototype has already been used in cognitive science to explain the incremental property of concept learning. The prototype model tries to create various new objects by providing a representative object as basis, from which more objects that are specialized to different applications can be created.
而原型-委托也是OOP中的对象抽象,代码共享机制中的一种。
And prototype-delegate is also one of the object abstraction, code-sharing protocols in OOP.
一个类提供了一个或者多个对象的通用性描叙。
A class provides a general description for one or many objects.
从形式化的观点看,类与类型有关,因此一个类相当于是从该类中产生的实例的集合。
From the formalized point of view, class is related to type. Therefore a class is equivalent to the collection of all instances that are derived from itself.
而这样的观点也会带来一些矛盾,比较典型的就是在继承体系下,子集(子类)对象和父集(父类)对象之间的行为相融性可能很难达到,这也就是OOP中常被引用的---子类型(subtype)不等于子类(subclass)[Budd 2002]。
Such viewpoints can also come into conflicts. One typical problem is under the inheritance system, it is difficult to achieve operational compatibility between subclass objects and parent class objects. This is the often-quoted result: subtype is not the same as subclass.
而在一种所有皆对象的世界观背景下,在类模型基础上还诞生出了一种拥有元类(metaclass)的新对象模型。
Still, under the world view of everything is an object, a new object model that includes metaclass is built on the basis of the class model.
即类本身也是一种其他类的对象。
That is, class itself is an object of other classes.
以上三种根本不同的观点各自定义了三种基于类(class-based),基于原型(prototype-based)和基于元类(metaclass-based)的对象模型。
These three distinct viewpoints discussed above have defined the three object models: class-based, prototype-based, and metaclass-based.
而这三种对象模型也就导致了许多不同的程序设计语言(如果我们暂时把静态与动态的差别放在一边)。
And the three object models have led to many different program design languages (if we overlook the static and dynamic differences for now).
是的,我们经常接触的C++,Java都是使用基于类的对象模型,但除此之外还有很多我们所没有接触的OOPL采用了完全不一样的对象模型,他们是在用另外一种观点诠释OOP的内涵。
Yes, C++, Java that we commonly use are both class-based object model. But aside from them, there are many object-oriented programming languages that we have not used, which use completely different object models. They define the essence of OOP from a different point of view.
呼……累死我了。完全手翻,我在国外念CS,虽然不是研究语言的,但是自信翻译得八九不离十了。
Shift: TShiftState; X, Y: Integer);
var
Temp: TButton;
begin
Temp := TButton.Create(Form1);
Temp.Parent := Form1; // 问题A
Temp.Top := Y;
Temp.Left := X;
Temp.Width := Temp.Width + 100;
end;
这段代码如果缺了问题所在的那一段,那么按钮就不会出现,原因是什么呢?我才学OOP,您们如何理解这个Parent 呢?是不是说如果没有 Parent 那么Button 就没有生根的地方?
却是如此,我试了一下,如果Parent 写成 另外的一个很大的按钮(半个窗体大小的)或者组件,那么按钮就会在所定义的那个组件上面出现,不过这个问题 已经写了,还是问吧,老虾可不可以讲讲原理呢?
我是从Turbo Basic 转行到 Delphi, 现在全力学习 OOP 思想,请多关照!
Parent为包含该控件的父控件,这不是OOP的思想,是‘MS的MDI思想’
父组件,容器
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Panel2: TPanel;
procedure Button1Click(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Panel2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Parent := Panel1;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
procedure TForm1.Panel1Click(Sender: TObject);
begin
Button1.Parent := Panel1;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
procedure TForm1.Panel2Click(Sender: TObject);
begin
Button1.Parent := Panel2;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
end.
这个不是OOP的东西,windows的东西
当设置Parent时,会导致delphi调用DestroyHandle,
接着调用CreateHandle,
重建Button, 在CreateParams时,
if Parent <> nil then
WndParent := Parent.GetHandle
取相应的Parent的Handle,
然后CreateWindowEx,
恐怕不能放到一个很大的按钮上,因为Parent必须是个容器,象:form,panel,groupbox……
>恐怕不能放到一个很大的按钮上,因为Parent必须是个容器,象:form,panel,groupbox
The fact is I put the buttons on a very large button!!!!
Many originality of the OOP thought all come it is at the Simula language, and at Smalltalk language of perfect get to morely expand with standardize in the process with to before of thought of afresh comment.Can say that OO thought and OOPL are an almost synchronous development to promote mutually.And what the function type program design(logic-programming) of program design(functional-programming) and logic type represent close at the machine of actual calculation model different BE, the OOP almost led into precision of mathematics copy Xu, but a trait of builds up an object model, it can look like of reflect the relation of of apply entity in the realm, its essence is more close cognize at a kind of mankind thing adopt of the calculation model of philosophy view.Caused from here a topic of nature, what be that be the OOP exactly is?[D&T 1988][B.S 1991] ..In the OOP, the object is to compute corpus, own an own name, appearance and accept connect of outside news.Produce new object in the object model, the old object destroy, send out news and respond to news to constitute an OOP calculation the root of the model.
The creation of object contains two kinds of basic ways.1 kind takes prototype(prototype) object as foundation to produce new object.1 kind takes type(class) as the foundation creation new object.The concept of prototype has already been used to hermeneutic concept to study in the cognition the psychology of pass and increase characteristic, the prototype is to attempt to pass to provide an object which has a representative as foundation to produce various new object, and continue to produce to match actual and applied object more from here.And prototype-entrust is also that the object in the OOP is abstract, the code shares a kind within mechanism.A the in general use which provided a perhaps several objects copies Xu.See from the formal standpoint, the type relates to type, so an equal hence from that type ofly gather of output solid example.And so of the standpoint will also bring some antinomies, more typical be while inherit the system, the son gather(son) the behavior of that object and father gather(father) object to mutually melt sex and may can hardly attain, this is also in the OOP to be often quote from of-the sub- type(subtype) be unequal to son(subclass)[the Budd be 2002].But under the global view background that a kind of all all object, at type's model foundation last still is born 1 kind own the new object model of dollar(metaclass).Then the type is also a kind of other object.Three kinds of above standpoints with different root respectively defined 3 kinds according to the type(class-based), according to the object model of the prototype(prototype-based) and dollar(metaclass-based).And these three kinds of object models also caused many different program design languages.(if we temporarily put the difference of the static state and the dynamic state in the part)Yes, we usually contiguous C++, the Javas all use according to the object model of type, but in addition still had a lot of contiguous OOPLs that we have no to adopt completely different object model and they are use the content of moreover a kind of standpoint annotation OOP.
OOP many originalities the thoughts are all come it in language of Simula, and at Smalltalk language of perfect get to expand morely with standardize in the process and to past of thought afresh comment.Can say the OO the thought and OOPL is almost a synchronous development to promote mutually.With the function type program design( functional- programming) different from the logic type program design( logic- programming) representative of near to in the actual calculation model of the machine is, the OOP almost did not lead into mathematics of the precision to copy the 叙 , but incline toward to build up an object model, the relation between entity in the reflection application realm that it can look like, its essence even is near to in a kind of mankind the calculation model of the philosophy view that the cognition thing adopt.From here, cause a topic of nature, is that what is the OOP exactly?[D&T 1988][B.S 1991] ..In the OOP, the object conduct and actions calculation corpus, own own name, appearance and accept the outside news to connect.In the object model, new object of creation, the old object destroy by burning, sending out the news, responding to the news and then constitute the OOP to compute the root of the model.
The creation of the object contain two kinds of basic ways.A kind of take the prototype( prototype) object as the foundation to produce the new object.A kind of is to take type( class) as the foundation to produce the new object.The concept of the prototype hases already been use in cognize psychology to come to explain the concept to study of pass and increase characteristic, the prototype is to attempt to pass to provide an object that has the representative as foundation to produce various new object, and continue to produce to even match the actual and applied object from here.And prototype- entrust is also an object in the OOP abstract, the code share a kind within mechanism.A provided an or several object of in general use copy the 叙 .See from the formal standpoint, the type has something to do with type, so an equal hence from that type of in the output solid example gather.And such standpoint also will bring some antinomies, comparing the typical model is while inherit the system, the son gather( son) the behavior that the object and fathers gather( father) the of object and melt sex and may can hardly attain mutually, this also is in the OOP to was often quote from of- the sub- type( subtype) is unequal to son( subclass)[2002] of Budd.But under a kind ofly the havings all the global view background of the object, still bore on a model foundation a kind of new object model that owns dollar( metaclass).Then the type is also a kind of other object.Above each of three kinds of basically different standpointseses defined three kinds of according to type( class- based), according to the object model of the prototype( prototype- based) and dollar( metaclass- based).And these three kinds of object models also caused many different program design languages.( if we temporarily put the aside to the difference of the static state and dynamic state)Yes, the C that we usually get in touch with++, the Javas all use according to the object model of the type, but in addition plenty more contiguous OOPL that we have no adopted the complete different object model, they is to use the content that another kind of standpoint explains the OOP.
Shift: TShiftState; X, Y: Integer);
var
Temp: TButton;
begin
Temp.Parent := Form1; // 问题A
Temp.Top := Y;
Temp.Left := X;
Temp.Width := Temp.Width + 100;
end;
这段代码如果缺了问题所在的那一段,那么按钮就不会出现,原因是什么呢?我才学OOP,您们如何理解这个Parent 呢?是不是说如果没有 Parent 那么Button 就没有生根的地方?
却是如此,我试了一下,如果Parent 写成 另外的一个很大的按钮(半个窗体大小的)或者组件,那么按钮就会在所定义的那个组件上面出现,不过这个问题 已经写了,还是问吧,老虾可不可以讲讲原理呢?
我是从Turbo Basic 转行到 Delphi, 现在全力学习 OOP 思想,请多关照!
Parent为包含该控件的父控件,这不是OOP的思想,是‘MS的MDI思想’
父组件,容器
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Panel2: TPanel;
procedure Button1Click(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Panel2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Parent := Panel1;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
procedure TForm1.Panel1Click(Sender: TObject);
begin
Button1.Parent := Panel1;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
procedure TForm1.Panel2Click(Sender: TObject);
begin
Button1.Parent := Panel2;
Button1.SetBounds(0, 0, Button1.Width, Button1.Height);
end;
end.
这个不是OOP的东西,windows的东西
当设置Parent时,会导致delphi调用DestroyHandle,
接着调用CreateHandle,
重建Button, 在CreateParams时,
if Parent <> nil then
WndParent := Parent.GetHandle
取相应的Parent的Handle,
然后CreateWindowEx,
恐怕不能放到一个很大的按钮上,因为Parent必须是个容器,象:form,panel,groupbox……
>恐怕不能放到一个很大的按钮上,因为Parent必须是个容器,象:form,panel,groupbox
The fact is I put the buttons on a very large button!!!!