什么是OOP的术语和复杂性? [英] what's OOP's jargons and complexities?

查看:103
本文介绍了什么是OOP的术语和复杂性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在计算机语言中,函数定义通常如下所示:


子程序f(x1,x2,...){

变量.. 。

用LISP系列等高级语言做这个或那个

}


,定义
的情况并不少见/>
函数内部函数。例如:


子程序f(x1,x2,...){

变量...

子程序f1( x1 ...){...}

子程序f2(x1 ...){...}

}


通常这些f1 f2内部函数在f中使用,而不是在f之外相关的
。这种语言的力量逐渐发展成为一种编程风格。例如:


子程序a_surface(){

coordinatesList = ...;

子程序翻译(距离){.. 。}

子程序旋转(角度){..}

}


这样的风格是a_surface不再作为一个函数被视为。

而是一组盒装函数,以一段数据为中心。

并且,所有用于操作这些数据的函数都体现了

这个函数。例如:


子程序a_surface(arg){

coordinatesList = ...

子程序translate(distance){set coordinatesList翻译

版}

子程序旋转(角度){将coordinatesList设置为旋转版本}

子程序return(){return coordinatesList}


if(no arg){return coordinatesList}

else {apply arg to coordinatesList}

}

通过这种方式,一个人使用a_surface作为数据,它附带了它的欠款集

的函数:


mySurface = a_surface() ;

a_surface(旋转(角度)); #现在表面数据已经旋转

a_surface(translate(distance)); #现在已翻译

myNewSurface = a_surface(return())


现在,a_surface不再被视为子程序,而是一个盒装集合/>
以数据为中心的事物。所有适用于数据的函数都包含在盒装集中。

函数式语言中提供的这种范例已经得到了很大的改进,以至于它传播到其他的b $ b组,它们被称为面向对象的编程,并且完成了
$ b出现了带有新语法的$ b语言迎合了这种方案。


在这些语言中,不要像这样编写它们:


mySurface = a_surface ();

a_surface(旋转(角度));


语法改为这样,例如:


mySurface = new a_surface();

mySurfaceRotated = mySurface.rotate(angle);


在这些语言中,超级子程序a_surface是no更长的称为

函数或子程序。它们现在称为类。现在

变量mySurface = a_surface()现在称为对象。函数a_surface()中的

子程序不再被称为

内部子程序。它们被称为方法。


这种编程和语言风格变得如此狂热,以至于在这种专用语言如Java,语言中的一切是

Classes。人们不能只定义一个变量或子程序。

而是创建这些元子程序Classes。所做的一切都是在Blasses里面。并且在这些类中分配变量以

创建对象。并且使用方法和方法。操纵对象。在这种

方式中,即使是数字,字符串和列表等数据类型也不再是原子数据类型。它们现在是类。


例如,在Java中,字符串是类String。在类内部

String中,有一些方法可以操作字符串,例如查找字符串的数量,或者提取部分字符串。这可能会非常复杂。例如,在Java中,实际上有两类

字符串:一个是String,另一个是StringBuffer。哪一个使用

取决于你是否打算更改数据。


所以,这是一个简单的代码,用普通语言:


a ="一个字符串" ;;

b ="另一个" ;;

c = join(a,b);

打印c;


或lisp风格


(设置一个字符串)

(设b另一个)

(设置c(加入ab))

(打印c)


变成纯OOP语言:


公共类测试{

public static void main(String [] args){

String a = new String(" a string");

String b = new String(" another one");

StringBuffer c = new StringBuffer(40);

c.append(a); c.append(b);

System.out.println(c.toString());

}

}


这里,new String创建一个String对象。 new

StringBuffer(40)

创建可更改的字符串对象StringBuffer,空间为40

字符。 "将"是StringBuffer的一种方法。它用于连接两个

字符串。


注意语法c.append(a),我们可以将其视为调用a

内部子程序追加,在已经分配给b的超级子程序上,其中,内部子程序通过追加来修改内部数据

a。


在上面的Java示例中,StringBuffer类有另一种方法

" toString()"用于将其转换为String类,必需

因为System.out.println'的参数需要String类型,而不是

StringBuffer。


有关类和方法复杂性的示例,请参阅

文档。 //java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html\"target =_ blank> http://java.sun.com/j2se/1.4.2/docs/ ... ingBuffer.html



以同样的方式,Java中的数字已成为许多

类的正式化:Double,Float,整数,长...并且每个都有一堆

"方法"操作或从一个转换为另一个。


而不是


aNumber = 3;

打印aNumber ^ 3;


在Java中程序员需要掌握几个

数字类的来龙去脉,并决定使用哪一个。 (如果一个程序后来需要从一种类型的数字改为另一种类型,那通常很麻烦。)


这种面向对象的编程风格和专用语言(如

C ++,Java)已经成为业界流行程序中的一种狂热之火。部分是因为以数据为中心的新视角,部分是因为新语法的新颖性和神秘性以及

行话化。


机会主义者Sun Microsystems特别大肆炒作,1995年左右,Java,互联网和网络应用程序开始兴起。在这些时候,OOP(和Java)是我们认为要彻底改变行业,并解决所有软件工程问题,特别是通过某些b $ b组件的重复使用来解决所有问题。被认为与OOP一起提出的概念。


作为这种新语法和纯度的一部分,程序中的所有内容都是类,对象和方法的
在OOP中出现了许多复杂问题和

概念。


我们现在知道行话类最初是有效的只是一个

盒装的数据和子程序集,全部在子程序中定义。并且

行话对象只是一个已设置为此超级

子例程的变量。内部子程序就是所谓的方法。


-----------------


因为心理上的推动纯洁,在Java中不再有b $ b普通的子程序。一切都是某种阶级的方法。标准

的功能类似于打开文件,平方根数字,循环通过

列表,if else分支语句或简单算术运算......

现在必须有些如何成为某种类的方法。通过这种方式,OOP

层次结构诞生了。


基本数据类型,例如现在各种类型的数字,现在是

分组为Number类层次结构,每个类都有自己的set

方法。字符,字符串或其他数据类型被归为

一个数据类型的层次结构类。许多类型的列表(不同地称为数组,向量,列表,哈希等等),被集中到一个层次结构中,每个节点Classe都有自己的
适当地设定方法。数学

函数,被归入某些数学类层次结构。


现在假设加操作+,它在哪里?它应该成为数字标题下各种类的方法吗?或者它应该是数学类集的方法吗?每种语言处理这些问题

不同。例如,请参阅此页面了解Java'

核心语言类的层次结构:
http://java.sun.com/j2se/1.4.2/docs/...kage- tree.html


层次结构概念与纯OOP纠缠在一起,因此OOP被错误地认为是具有层次结构的语言。 (现在还有

也就是所谓的面向对象的数据库,它们以所有数据的概念为中心的

概念树......)

>
通常在程序中,当我们想要做一些操作时,我们只需要调用

一些数据的子程序。比如


打开(this_file)

square(4)


但是现在用纯OOP风格,不能只是一个数字

或this_file路径,因为现在一切都必须是一个Object。因此,

this_file通常只是一个表示磁盘上

文件路径的字符串,现在是一些文件对象。由某事启动

喜欢


this_file =新文件(文件路径);


其中这个文件类有一堆方法,比如读或写

给它。


看到这个页面了解IO树的复杂性
http:// java.sun.com/j2se/1.4.2/docs/...kage-tree.html

请参阅此页面以获取File类本身的文档,沿着它的40个左右的方法和其他东西来获得

http://java.sun.com/j2se/1.4.2/docs/...a/io/File.html


明天我将覆盖OOP炒作中更多的人造术语和复杂性,特别是Java。


实例化

初始化器,构造函数,评估者

访问级别规范更好的

抽象类和抽象方法

实例方法和类方法

接口,继承,多态。

Xah
xa*@xahlee.org
http://xahlee.org/PageTwo_dir/more.html

解决方案



2005年1月29日00:10,Xah Lee写道:

明天我将覆盖更多的人造术语和复杂性
出于OOP炒作,特别是Java。




好​​读。让他们来吧:)


干杯


-

PA,Onnay Equitursay
http://alt.textdrive.com/




" Xah Lee" < xa*@xahlee.org>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

public class test {
public static void main(String [] args){
String a = new String(" a string");
String b = new String( 另一个);
StringBuffer c = new StringBuffer(40);
c.append(a); c.append(b);
System.out.println(c.toString());
}
}




实际上,它可以很简单:

公共类测试{

public static void main(String [] args){

String c = new String(" a string" +" another one");

System.out.println(c);

}

}


我不会进入你的历史 OOP炒作。




" Dan Perl" <哒***** @ rogers.com>在留言中写道

新闻:U9 ******************** @ rogers.com ...

其实,它可以简单如下:
public class test {
public static void main(String [] args){
String c = new String(" a string" +" another)一个);
System.out.println(c);
}
}




我忘了。它可以更简单:


公共类测试{

public static void main(String [] args){

System .out.println(" a string" +" another one");

}

}


in computer languages, often a function definition looks like this:

subroutine f (x1, x2, ...) {
variables ...
do this or that
}

in advanced languages such as LISP family, it is not uncommon to define
functions inside a function. For example:

subroutine f (x1, x2, ...) {
variables...
subroutine f1 (x1...) {...}
subroutine f2 (x1...) {...}
}

often these f1 f2 inner functions are used inside f, and are not
relevant outside of f. Such power of the language gradually developed
into a style of programing. For example:

subroutine a_surface () {
coordinatesList = ...;
subroutine translate (distance) {...}
subroutine rotate (angle) {..}
}

such a style is that the a_surface is no longer viewed as a function.
But instead, a boxed set of functions, centered around a piece of data.
And, all functions for manipulating this piece of data are all embodied
in this function. For example:

subroutine a_surface (arg) {
coordinatesList = ...
subroutine translate (distance) {set coordinatesList to translated
version}
subroutine rotate (angle) {set coordinatesList to rotated version}
subroutine return () {return coordinatesList}

if (no arg) {return coordinatesList}
else { apply arg to coordinatesList }
}

In this way, one uses a_surface as a data, which comes with its owe set
of functions:

mySurface = a_surface();
a_surface(rotate(angle)); # now the surface data has been rotated
a_surface(translate(distance)); # now its translated
myNewSurface = a_surface(return())

So now, a_surface is no longer viewed as a subroutine, but a boxed set
of things centered around a piece of data. All functions that work on
the data are included in the boxed set. This paradigm available in
functional languages has refined so much so that it spread to other
groups that it became knows as Object Oriented Programing, and complete
languages with new syntax catered to such scheme emerged.

In such languages, instead of writing them like this:

mySurface = a_surface();
a_surface(rotate(angle));

the syntax is changed to like this, for example:

mySurface = new a_surface();
mySurfaceRotated = mySurface.rotate(angle);

In such languages, the super subroutine a_surface is no longer called a
function or subroutine. They are now called a "Class". And now the
variable "mySurface = a_surface()" is now called a "Object". The
subroutines inside the function a_surface() is no longer called
inner-subroutines. They are called "Methods".

This style of programing and language have become so fanatical that in
such dedicated languages like Java, everything in the language are
"Classes". One can no longer just define a variable or subroutine.
Instead, one creates these meta-subroutine "Classes". Everything one do
are inside Classes. And one assign variables inside these Classes to
create "Objects". And one uses "Methods" to manipulate Objects. In this
fashion, even data types like numbers, strings, and lists are no longer
atomic data types. They are now Classes.

For example, in Java, a string is a class String. And inside the class
String, there are Methods to manipulate strings, such as finding the
number of chars, or extracting parts of the string. This can get very
complicated. For example, in Java, there are actually two Classes of
strings: One is String, and the other is StringBuffer. Which one to use
depends on whether you intend to change the data.

So, a simple code like this in normal languages:

a = "a string";
b = "another one";
c = join(a,b);
print c;

or in lisp style

(set a "a string")
(set b "another one")
(set c (join a b))
(print c)

becomes in pure OOP languages:

public class test {
public static void main(String[] args) {
String a = new String("a string");
String b = new String("another one");
StringBuffer c = new StringBuffer(40);
c.append(a); c.append(b);
System.out.println(c.toString());
}
}

here, the "new String" creates a String object. The "new
StringBuffer(40)"
creates the changeable string object StringBuffer, with room for 40
chars. "append" is a method of StringBuffer. It is used to join two
Strings.

Notice the syntax "c.append(a)", which we can view it as calling a
inner subroutine "append", on a super subroutine that has been assigned
to c, where, the inner subroutine modifies the inner data by appending
a to it.

And in the above Java example, StringBuffer class has another method
"toString()" used to convert this into a String Class, necessary
because System.out.println''s parameter requires a String type, not
StringBuffer.

For a example of the complexity of classes and methods, see the Java
documentation for the StringBuffer class at
http://java.sun.com/j2se/1.4.2/docs/...ingBuffer.html

in the same way, numbers in Java have become a formalization of many
classes: Double, Float, Integer, Long... and each has a bunch of
"methods" to operate or convert from one to the other.

Instead of

aNumber = 3;
print aNumber^3;

in Java the programer needs to master the ins and outs of the several
number classes, and decide which one to use. (and if a program later
needs to change from one type of number to another, it is often
cumbersome.)

This Object Oriented Programing style and dedicated languages (such as
C++, Java) have become a fad like wild fire among the programing
ignoramus mass in the industry. Partly because of the data-centric new
perspective, partly because the novelty and mysticism of new syntax and
jargonization.

It is especially hyped by the opportunist Sun Microsystems with the
inception of Java, internet, and web applications booms around 1995. At
those times, OOP (and Java) were thought to revolutionize the industry
and solve all software engineering problems, in particular by certain
"reuse of components" concept that was thought to come with OOP.

As part of this new syntax and purity, where everything in a program is
of Classes and Objects and Methods, many many complex issues and
concept have arisen in OOP.

we now know that the jargon Class is originally and effectively just a
boxed set of data and subroutines, all defined inside a subroutine. And
the jargon "Object" is just a variable that has been set to this super
subroutine. And the inner subroutines are what''s called Methods.

-----------------

because of psychological push for purity, in Java there are no longer
plain subroutines. Everything is a method of some class. Standard
functions like opening a file, square root a number, for loop thru a
list, if else branching statements, or simple arithmetic operations...
must now some how become a method of some class. In this way, the OOP
Hierarchy is born.

Basic data types such as now the various classes of numbers, are now
grouped into a Number class hierarchy, each class having their own set
of methods. The characters, string or other data types, are lumped into
one hierarchy class of data types. Many types of lists (variously known
as arrays, vectors, lists, hashes...), are lumped into a one hierarchy,
with each node Classe having their own set methods as appropriate. Math
functions, are lumped into some math class hierarchy.

Now suppose the plus operation +, where does it go? Should it become
methods of the various classes under Number headings, or should it be
methods of the Math class set? Each language deals with these issues
differently. As a example, see this page for the hierarchy of Java''s
core language classes:
http://java.sun.com/j2se/1.4.2/docs/...kage-tree.html

The hierarchy concept is so entangled in pure OOP such that OOP is
erroneously thought of as languages with a hierarchy. (there are now
also so-called Object-Oriented databases that are centered on the
concept of all data are trees ...)

Normally in a program, when we want to do some operation we just call
the subroutine on some data. Such as

open(this_file)
square(4)

But now with the pure OOP style, there can no longer be just a number
or this_file path, because everything now must be a Object. So, the
"this_file", usually being just a string representing the path to a
file on the disk, is now some "file object". Initiated by something
like

this_file = new File("path to file");

where this file class has a bunch of methods such as reading or writing
to it.

see this page for the complexity of the IO tree
http://java.sun.com/j2se/1.4.2/docs/...kage-tree.html

see this page for the documentation of the File class itself, along
with its 40 or so methods and other things.
http://java.sun.com/j2se/1.4.2/docs/...a/io/File.html

Tomorrow i shall cover more manmade jargons and complexities arising
out of the OOP hype, in particular Java.

instantiation
initializer, constructor, assessor
access level specifier
abstract class and abstract methods
instance methods and class methods
interface, inheritance, polymorphism.
Xah
xa*@xahlee.org
http://xahlee.org/PageTwo_dir/more.html

解决方案


On Jan 29, 2005, at 00:10, Xah Lee wrote:

Tomorrow i shall cover more manmade jargons and complexities arising
out of the OOP hype, in particular Java.



Good read. Keep them coming :)

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/



"Xah Lee" <xa*@xahlee.org> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

public class test {
public static void main(String[] args) {
String a = new String("a string");
String b = new String("another one");
StringBuffer c = new StringBuffer(40);
c.append(a); c.append(b);
System.out.println(c.toString());
}
}



Actually, it can be as simple as:
public class test {
public static void main(String[] args) {
String c = new String("a string"+" another one");
System.out.println(c);
}
}

I will not get into your "history" of the "OOP hype".



"Dan Perl" <da*****@rogers.com> wrote in message
news:U9********************@rogers.com...

Actually, it can be as simple as:
public class test {
public static void main(String[] args) {
String c = new String("a string"+" another one");
System.out.println(c);
}
}



I forgot. It can be even simpler:

public class test {
public static void main(String[] args) {
System.out.println("a string"+" another one");
}
}


这篇关于什么是OOP的术语和复杂性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆