什么是OOP的学校? [英] What are the schools of OOP?

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

问题描述

是否有Smalltalk的面向对象和面向对象的Simula的哲学之间的差异

Are there philosophical differences between Smalltalk OOP and Simula OOP ?

这是与Java和功放的问题?; C#VS C ++间接的影响。据我所知,C ++是基于西穆拉但Java和C#是从Smalltalk的家庭或多或少。

This is a question related to Java & C# vs C++ indirectly. As I understand, C++ is based on Simula but Java and C# are more or less from the Smalltalk family.

推荐答案

几个关键在更广泛的面向对象的横幅中的'风格'的区别。

Several key 'differences in 'Style' within the broader OOP banner.

在所有情况下,有关语句的静态动态的类型系统是指主要是一个或另一个,这个问题还远远没有明确的或明确的规定。
也有许多语言中选择模糊的选择之间的界限,所以这是不以任何方式二进制选项列表

In all cases a statement about a static or dynamic type system means predominately one or the other, the issue is far from clear cut or clearly defined. Also many languages choose the blur the line between the choices so this is not a list of binary choices by any means.

或是什么 foo.Bar (X)的意思吗?


  1. 的类型层次扁平化到每个实例的具体实现(通常是通过做一个虚表的),并通常允许明确提及的基类实现。

    • 从概念上讲,你看的最具体类型foo是调用点。如果它具有的参数x被调用,如果选择不foo的父并重复该处理栏的实现。

    • 例如:C ++ / Java的/ C#,西穆拉风格经常被使用。

  1. Hierarchy of types is flattened to a specific implementation per instance (often done via a vtable) and often allowing explicit reference to the base classes implementation.
    • Conceptually you look at the most specific type that foo is at the callsite. If it has an implementation of Bar for the parameter x that is called, if not the parent of foo is chosen and the process repeated.
    • Examples: C++/Java/C#, "Simula style" is often used.
  • Examples: Objective-C/Ruby, "Smalltalk style" is often used.

通常使用1静态类型的框架,它是一个误差范围内,检查在编译的时候没有这样的实施存在。进一步语言常常栏(x)和酒吧(y)的区分,如果x和y是不同的类型。这是方法重载和具有相同的名称所产生的方法被视为完全不同的

1 is often used within statically typed frameworks where it is an error, checked at compile time for no such implementation to exist. Further the languages often differentiate between Bar(x) and Bar(y) if x and y are different types. This is method overloading and the resulting methods with the same name are viewed as entirely different.

2通常是在动态语言(其倾向于避免方法重载),为这样使用可能的是,在运行时foo的类型已名为酒吧消息没有'处理',不同的语言以不同的方式处理此

2 is often used in dynamic languages (which tend to avoid method overloading) as such it is possible that, at runtime the type of foo has no 'handler' for the message named 'Bar', different languages handle this in different ways.

两者都可以如果需要以相同的方式在幕后实施(通常为第二默认,Smalltalk的风格是调用一个函数,但这不是由在所有情况下定义的行为)。
由于前一种方法常常可以方便地作为简单的指针偏移函数调用来执行它可以更容易,可以制成比较快的。这并不意味着其他样式不能也可制成快,但更多的工作,可能需要确保这样做时有更大的灵活性不会受到损害。

Both can be implemented behind the scenes in the same fashion if desired (often the default for the second, Smalltalk style is to invoke a function but this is not made a defined behaviour in all cases). Since the former method can frequently be easily implemented as simple pointer offset function calls it can, more easily, be made relatively fast. This does not mean that the other styles cannot also be made fast, but more work may be required to ensure that the greater flexibility is not compromised when doing so.

或在哪里宝宝是从哪里来的?

or "Where do babies come from?"


  1. 基于类

    • 方法实现组织成称为组类。当实现继承需要一个类定义了扩展的父类。通过这种方式,获得的所有的暴露父的各个方面(包括属性和方法),并可以选择改变某些/所有这些方面,但的无法的删除任何。您可以添加和更新,但不能删除

    • 例子:C ++ / Java的/ C#(注意这两种Smalltalk和Simula的使用)

  1. Class based
    • Method implementations are organized into groups called classes. When implementation inheritance is desired a class is defined which extends the parent class. In this way it gains all exposed aspects of the parent (both fields and methods) and can choose to alter certain/all of those aspects but cannot remove any. You can add and update but not delete.
    • Examples: C++/Java/C# (note both SmallTalk and Simula use this)

  • 一个对象的任何实例只是认定方法的集合(通常由名称标识)及状态(再次入选)字段的形式。每当这个'类型'的一个新实例期望现有实例可用于克隆一个新的。这个新的类保留了状态和以前的类的方法的一个副本,然后可以修改,删除,添加或更改现有的命名字段和方法

  • 例子:自/ JavaScript的

  • Any instance of an object is simply a collection of identified methods (normally identified by name) and state in the form of (again named) fields. Whenever a new instance of this 'type' is desired an existing instance can be used to clone a new one. This new class retains a copy of the state and methods of the previous class but can then be modified to remove, add or alter existing named fields and methods.
  • Examples: Self/JavaScript

1再次趋于静态语言发生,2在动态虽然这绝不是他们只是借给自己风格的要求。

Again 1 tends to happen in static languages, 2 in dynamic though this is by no means a requirement they simply lend themselves to the style.

或什么,或者怎么样?


  • 例如:VB6

  1. Interfaces list the methods that are required. They are a contract
    • Examples: VB6

  • 实例类名单的方法:西穆拉

  • Examples: Simula

这是非常不二元选择。大多数基于类的语言允许的抽象方法的概念(那些没有实现还)。如果你有一个类,所有方法都是抽象的(称为纯虚的C ++)类的数额是那么什么非常的接口,尽管它也可能已经定义了一些状态(字段)。一个真正的接口应该没有状态(因为它定义的只有的什么是可能的,而不是它是如何发生的。

This is very much not a binary choice. Most class based languages allow the concept of abstract methods (ones with no implementation yet). If you have a class where all methods are abstract (called pure virtual in C++) then what the class amounts to is pretty much an interface, albeit one that may have also defined some state (fields). An true Interface should have no state (since it defines only what is possible, not how it happens.

只有较早OOP语言倾向于依靠单靠一方或另一方。

VB6只有在接口上,没有实现继承。

西穆拉让你声明纯虚类,但你可以实例化它们(与运行时错误上使用)

Only older OOP languages tend to rely solely on one or the other.
VB6 has only on interfaces and have no implementation inheritance.
Simula let you declare pure virtual classes but you could instantiate them (with runtime errors on use)

或谁是爸爸?




    • 只有一种类型可以是父到另一个地方。在基于类的形式上面可以扩展(需要从实现)只有一种类型,通常这种形式包括作为语言的头等方面接口的概念来弥补这一点。

    • 的优势包括更清洁的元数据和反省,更简单语言规则。

    • 并发症包括使其更难把有用的方法为范围(之类的东西混入扩展方法寻求减轻这类问题)

    • 例如:C#/ JAVA

  1. Single
    • Only one type can be a parent to another. In the Class based form above you can extend (take implementation from) only one type. Typically this form includes the concept of interfaces as first class aspects of the language to make up for this.
    • advantages include cleaner metadata and introspection, simpler language rules.
    • complications include making it harder to bring useful methods into scope (things like MixIns and Extension methods seek to mitigate this sort of problem)
    • Examples: C#/java

  • 的优势包括一些结构更容易建模和设计

  • 的并发症包括冲突解决复杂的规则,尤其是当重载方法存在这可能需要父母任何一方键入

  • 例如:C ++ /艾菲尔

  • advantages include certain structures are easier to model and design
  • complications include complex rules for collision resolution, especially when overloaded methods exist which could take either parent type.
  • Examples: C++/Eiffel

这问题引发相当大的争议,特别是因为它是C ++的面向对象的实施,许多人认为像C#和Java可能的接班人现代静态类型语言之间的关键区别。

This question provokes considerable debate, especially as it is a key differentiator between C++'s OOP implementation and many of the modern statically typed languages perceived as possible successors like c# and java.

或你要对我做什么呢?


  1. 可变

    • ,曾经创造可以有自己的状态的对象变了。


  • 对象,一旦创建不能改变。

通常这不是一个全有或全无它仅仅是一个默认的(最常用的OOP语言默认为可变默认情况下)。这可以对语言的结构如何影响很大。其中包括OOP许多主要功能的语言功能默认的对象具有不可变的状态。

Frequently this is not an all or nothing it is simply a default (most commonly used OOP languages default to mutable by default). This can have a great deal of affect on how the language is structured. Many primarily functional languages which have included OOP features default the objects to have immutable state.

或者一切对象?


  1. 在系统绝对一切都被看作是一个对象(甚至可能下降到方法本身这只是另一种对象,而且可以用相同的方式的其他对象可以是可交互)。

    • 例如:Smalltalk的

  1. Absolutely everything in the system is viewed as an object (possibly even down to the methods themselves which are simply another kind of object and can be interacted with in the same way other objects can be).
    • Examples: SmallTalk

  • 例如:C ++ / C#/ Java的(见注释的)_

  • Examples: C++/C#/Java (see note)_

这是因为像技术相当复杂原语的自动装箱使它看起来像一切,但你会发现,存在多个边界的情况下,这个神奇的编译器'被发现和奥兹的谚语向导发现背后产生的帘问题或错误。
在与不可改变作为默认这是不太可能发生,因为对象的关键方面(即它们含有两种方法和状态的)的语言表示的东西都是相似的对象,但不颇有并发症的可能性较小。

This is quite complex since techniques like auto boxing of primitives make it seem like everything is but you will find that several boundary cases exist where this 'compiler magic' is discovered and the proverbial wizard of Oz is found behind the curtain resulting is problems or errors. In languages with immutability as a default this is less likely to happen, since the key aspect of objects (that they contain both methods and state) means that things that are similar to objects but not quite have less possibility for complications.


  • 在问候的Java / C#中的自动装箱(或的 C#)系统,可以让你请客,语法的,如果它是一个对象,但实际上这是不是这样的,这是在地区展出,如试图锁定在任何变量autoboxed对象(由编译器拒绝,因为这将是一个明显的bug)。

  • In regards to Java/C# the autoboxing(or in c#) system lets you treat, syntactically any variable as if it was an object but, in actuality this is not the case and this is exhibited in areas such as attempting to lock on an autoboxed object (rejected by the compiler as it would be an obvious bug).

或你以为你是谁?

语言设计的更为普遍的方面,并没有一个进入这里,但选择正如前面所提到的固有的这一决定影响OOP的许多方面

A far more pervasive aspect of language design and not one to get into here but the choices inherent in this decision impact many aspects of OOP as mentioned earlier.

多态性后期绑定可以依靠的只是几个方面:

Just aspects of the polymorphic late binding can depend on:


  • 类型的对象被传递人的消息(在编译时/运行时间)

  • 的类型参数(<强>取值这是传递(在编译时/运行时间))

  • The type of the object to whom the message is being passed (at compile time/run time)
  • The type of the parameter(s) which are being passed (at compile time/run time)

更具活力的语言得到更多的复杂的这些决定往往成为但反过来的多个输入的语言的用户,而不是语言的设计者的具有该决定。
在这里给出的例子是一些什么有勇无谋,因为静态类型语言可以被修改,以包括动态方面(如C#4.0)。

The more dynamic a language gets the more complex these decisions tend to become but conversely the more input the language user, rather than the language designer has in the decision. Giving examples here would be some what foolhardy since statically typed languages may be modified to include dynamic aspects (like c# 4.0).

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

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