Object-oriented this thing, in fact, we have not felt that they are in use, I must use in the future. I used to learn C # when seriously looked at once, has been studying Java. Just take a look.
Polymorphic problem:
Polymorphism in Java is divided into (1) compile-time polymorphism and (2) Run-time polymorphism
(1) Compile-time polymorphism is easy to understand: in fact, by means of overloading, is the method of overloading, the same function name but can be different parameters. This is the overload (so easy)
(2) Run-time polymorphism: This is done through method overrides, that is, when the subclass inherits the parent class, overwrites the parent class method by overriding the method.
To put it simply: for example, we have a parent class A, subclass B inherits the A,c,d through extends, and we just use call a when we call the method.
(using the parent class reference to point to the subclass object, when calling a method in a parent class, different subclasses will show different method results, which is polymorphism, inheritance is polymorphic)
Function: Extensibility is good, we add a class, as long as the inherited parent class, and overwrite the parent class method OK. A variety of implementations of an interface, the performance of inheritance is polymorphism.
(The application does not have to write a feature call to each derived class, only the abstract base class must be processed)
I added the rationale for using the interface: It allows us to create more generic code, writing code for interfaces rather than concrete implementation classes, so that our code can apply more object types.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/
Container:
We use more certainly is list<t> list=new Arraylist<t>, undeniable ArrayList is very powerful, but in fact Java also has many other good things.
First of all to explain that the list is an interface, not list X=new list (), the list just declared the function, and did not implement. ArrayList is a concrete implementation class that inherits the list.
(1) Array: When it comes to containers, you might want to refer to the array, so, for the time being, see that the array is a fixed size container (in fact, it is not a container), and then because the size of the array, so the parameters can be randomly accessed, the speed should be the fastest One thing to note is that the legths of the array is the size of the array rather than the number of data inside the array.
(2) The difference between collection and collections
Collection is the top-level interface of the collection class, which also has the list and set two interfaces below it (interface inheritance interface)
Collections is a tool class for the collection class, which provides a series of static functions that can be used to sort the collection and select the maximum value ...
(3) Diagram to illustrate the relationship (and map, it is and collection a level, including hashtable,hashmap ...). )
(4) iterator (iterator)
An iterator is a design pattern, and it's a damn design pattern. We know that iterators are used to select collection objects, and we select object references through iterators to manipulate objects directly. Code I will not post it.
Role: As a design pattern, you can apply different types of containers without having to know or rewrite the code.
This may not be understood, so to speak: we can do without the control of how the collection is implemented, whether he is a list or a map, I just need to call the iterator on the OK. In fact, the general time is not used, may be in your
Used when you want to change the collection implementation method of a program.
Author: blog Park Guo Jiasheng haha