It 18 palm Palm Six Day course summary

Source: Internet
Author: User

Finish the sixth day of it 18 Palm Java Foundation Course today:


Learning content:

1, interface and abstract class:

Interface

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

1, all methods are abstract

2, the property has a public static final decoration, which is the default, which means that the interface property is a static constant.

3, the interface can be multiple inheritance,

4, an inheritance relationship between interfaces

5, the implementation relationship is between the class and the interface.

6, interface-oriented programming to reduce coupling degree


Abstract class

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

1.abstract class

2. The class in which the abstract method resides must be abstract.

3. Abstract classes can have no abstract methods.

The similarities and differences between interfaces and abstract classes:

The same: Are abstract concepts that are constantly extracted

Difference 1:|--abstract class embodies inheritance relationship, one class can only inherit

|--interface embodies the realization of the relationship, a class can implement multiple interfaces

The difference between the 2:|--abstract class is inheritance, is the "is a" relationship

|--abstract class is internship that, is "like a" relationship

The difference between 3:|--abstract classes can define non-abstract methods for the subclasses to use directly

The methods of the |--interface are abstract, and the members in the interface have fixed modifiers.

2, adapter design mode

There are many abstract methods in the interface, in the production environment, we sometimes need only a few fixed methods, in the implementation of the interface class, not only need to focus on the fixed several methods, but also need to do not care about the abstract method specific coverage. This can lead to a bloated code. Adapter design pattern is to solve this problem, by creating an abstract class to implement the interface, and then just docking the mouth of the not concerned. Abstract methods do simple overwrite operations, preserving the abstract methods we need. The class inherits the abstract class when it is created, and we only need it. It's OK to cover the few abstract methods that we've fixed using, saving the amount of code.


Adapter Chinese Meaning: Suitable configuration, power adapter: The voltage from 220v to fit into the mobile phone charging voltage 5v.

Interface USB

{

void Gongdian ();

void DownLoad ();

}

Abstract Downloadadapter Implement USB

{

public void Gongdian ();

}

Class Needdownloaddemo extends Downloadadapter

{

public void DownLoad () {...}

}


3, polymorphic

1, a variety of forms of a thing

2, for inherited classes, use the parent class type to refer to the object of the child class

3, for an interface, you can use an interface to reference an object created by a class that implements the interface.


Methods can be overridden by a quilt class, and properties cannot be overwritten. Why?

A property is an asset that holds data where the function is behaving, does not hold and stores data, so functions can be overwritten, and properties cannot.

Prerequisites for polymorphism:

1, interface or inheritance

2, overwrite (inheritance optional, interface implementation class must overwrite)

4, Inner class

A class is defined inside another class, which is called an inner class (built-in class, nested Class).

Access features:

Inner classes can access members in external classes directly, including private members.

The external class must establish an inner class object to access the members of the inner class.

1, local inner class

Problems encountered:

1, interface adapter mode, button and listener knowledge is not familiar, string up.

Although the principle of adapter design pattern is understood, but lack of application experience

2, polymorphic member functions and member properties compile and run the reference process,

In summary: The member function can be overridden, the member property belongs to the asset of the class, and is used to hold the data and cannot be overwritten.

3, Inner class call rule



Questions that need help

1, inner class call rule

2, adapter application scenario

3, buttons and listeners


This article from "Rookie Achievement Data Road" blog, reproduced please contact the author!

It 18 palm palm six-day course summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.