合并课程意味着什么? [英] What does it mean consolidation classes?

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

问题描述

我想把我创建它们的所有对象从不同的类放在一个ArrayList中!!



我尝试了什么:



i希望将我创建它们的所有对象放在一个ArrayList的不同类中!!

i want to put all the objects that i created them from different classes in one ArrayList!!

What I have tried:

i want to put all the objects that i created them from different classes in one ArrayList!!

推荐答案

我不认为合并类这个术语在这方面具有决定性意义。你所谈论的是最基本的编程之一,OOP的核心概念之一,多态多态性(计算机科学) - 维基百科,免费的百科全书 [ ^ ]。



请注意类 ArrayList< E> 是遗传类: ArrayList(Java Platform SE 7) [< a href =https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html\"target =_ blanktitle =New Window> ^ ]。



具有泛型类的事实一般与多态或OOP无关,但它为您提供了一种定义编译时的方法列表元素类型的类型。 OOP多态性的基础是:它应该是接口类型,或者是可以扩展的类。实际上,类应该有虚方法,通常是 abstract pseudo-abstract ;这个课通常是抽象的,但并非总是如此。这种类型的接口(编译时类型)允许分配给几个不同的运行时类型的某些派生类。这些不同类型的集合使您成为那些不同类型的对象的多态集合。这已经回答了你的问题。



此时,您必须了解派生类或实现接口的类之间的赋值兼容性背后的OOP规则和基本原理。您还应该了解那些运行时类型与编译时类型。



形式上,虚拟方法(和属性)不是必需的,但如果没有它们,整个活动将毫无意义。整个想法是由基类/接口的成员专门操作多态集的所有对象(在您的情况下)。换句话说,你永远不应该询问什么是一个或另一个派生(运行时)类型,这只能通过后期绑定动态调度)基于虚方法/属性:动态调度 - 维基百科,免费的百科全书 [ ^ ]。



实际上,这个原则有时候会被<违反向下投射动态投射。只有在真正简化设计而没有太多额外风险的情况下才能完成这项工作,这被认为是正常的。



最后,接口的附加功能是多重继承。同一个对象可以实现两个不同的接口,因此可以参与两个不同的多态集或更多。这个好处不经常使用。



请查看我过去的答案:

抽象类的用途是什么?为什么我们不能创建抽象类的对象? [ ^ ],

我如何实现字符串函数和穷人的多元文化 [ ^ ],

多态性的使用? [ ^ ],

.net如何理解类型转换 [ ^ ],

运行时多态性VS编译时多态性 [ ^ ]。



对不起,上面引用的答案中只有一个是特定于Java的,其他的几乎是通用的,基于.NET,所以一些小问题可能不适用于Java;你不需要太注意;差异非常小。



-SA
I don't think the term "consolidation classes" means something definitive in this context. What you are talking about is one of the most fundamental programming things, one of the core concepts of OOP, polymorphism: Polymorphism (computer science) — Wikipedia, the free encyclopedia[^].

Note that the class ArrayList<E> is a genetic class: ArrayList (Java Platform SE 7)[^].

The fact of having a generic class has nothing to do with polymorphism or OOP in general, but it gives you a way to define a compile-time type of the type of a list element. The fundamental of OOP polymorphism is this: it should be either the interface type, or a class which can be extended. Practically, the class should have virtual methods, usually abstract or pseudo-abstract; and the class is usual abstract, but not always. This interface of class type, being a compile-time type, allows to be assigned to some derived classes of several different runtime types. The set of those different types makes you the polymorphic set of objects of those different types. That already answers your question.

At this point, you have to understand OOP rules and rationale behind assignment compatibility between derived classes or classes implementing a interface. You also should understand those runtime types vs compile-time ones.

Formally, virtual methods (and properties) are not required, but without them the whole activity would be pointless. The whole idea is to operate all objects of the polymorphic set (of your list, in your case) exclusively by the members of your base class/interface. In other words, you should never inquirer what is one or another derived (runtime) type, and this is only possible via late binding (dynamic dispatch) based on virtual methods/properties: Dynamic dispatch — Wikipedia, the free encyclopedia[^].

In practice, this principle is sometimes violated via the down-casting and dynamic cast. It this is done very rarely only when it is really simplifies design without much added risk, this is considered to be normal.

Finally, added power of interface is multiple inheritance. The same very object can implement two different interface and hence participate in two different polymorphic sets, or more. This benefit is not used often though.

Please see my past answers:
what is the use of abstract class ? and why can't we create object of abstract class?[^],
How Do I Implement "String Functions" And "Poor Man's Polymophism"[^],
The use of polymorphism ?[^],
How does .net understands about type casting[^],
run-time polymorphism VS compile-time polymorphism[^].

Sorry, only fist of the answers referenced above is specific to Java, others are pretty much universal and based on .NET, so some minor points could be inapplicable to Java; you don't need to pay much attention for that; the differences are really minor.

—SA


这篇关于合并课程意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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