Learn a little about flash (62) categories every day

Source: Internet
Author: User

This is a question that comes to mind today. What is the classification of classes? During programming, I feel that classes can be divided into many types of structures. Next I will record the situations I have encountered.

First, let's first understand the concept of "object and Class:

 

Object: an object that contains data and operations. It defines both data elements and operations that can be applied to these data elements.
Class: describes a group of objects with the same attributes and behaviors. The content of a class is called a member of a class.

 

From the concept, we can see that the object contains data and operations. In other words, attributes and methods are used. From the point of view of the set, the object contains attributes and methods.

You can use a class to create objects. We can start withClass contains objects and objects contain attributes and methods."Is a true proposition. Let's start today's topic.

 

A simple launch class contains attributes and methods.

 

 

Q: Do all classes have attributes? Is there a method for all classes?

This problem is a bit incorrect. The constructor is a method. Here we first exclude the existence of constructor methods. Next, let's continue our question: is all classes having properties?

Below is a simple example.

Class man <br/>{< br/> Public Function man () <br/>{< br/>}< br/> Public Function say (MSG: string ): string <br/>{< br/> return MSG; <br/>}</P> <p>

Therefore, the question is no, that is. Class does not contain attributes.

 

Next, will all classes have methods?

Class man <br/>{< br/> Public Function man () <br/>{< br/>}< br/> Public var Height: number; <br/>}< br/>

 

From this class, we can deny our problems, not necessarily. All classes do not necessarily contain methods (Note: Except the constructor, the previously described conditions ).

 

The answer to the two questions is as follows:

 

1. Some classes only contain attributes, which are called unique attribute classes;

2. Some classes only contain methods;

3. Some classes contain both methods and attributes, which are called normal classes;

 

 

With these inferences, we can expand the associations between the class's internal structure. First, the class contains only attributes. Let's look at the example below. It just lists the static attributes of a group of constants and does not write any other method.

 

The package <br/> {<br/> // orientation3d class is a constant value enumeration that represents the direction style of a matrix3d object. <Br/> // the three types of direction are the Euclidean angle, the axis angle, and the Quaternary element. <Br/> // The decompose and recompose methods of the matrix3d object use an enumeration type to identify the rotating component of the matrix. <Br/> Public final class orientation3d <br/> {<br/> // [Static] axis and angle are used in combination to determine the direction. <Br/> Public static const axis_angle: String = "axisangle"; </P> <p> // static] default direction of the decompose () and recompose () methods) define the direction through three different rotation angles corresponding to each axis. <Br/> Public static const euler_angles: String = "eulerangles"; </P> <p> // [Static] use the plural number in the direction of the Quaternary element. <Br/> Public static const quaternion: String = "quaternion"; <br/>}< br/>}

 

 

This class encapsulates the attributes of an object and there are no other methods. (In addition, you can name this type as an enumeration class)

 

Type 2 Structure: Unique Method type;

Class man <br/>{< br/> Public Function man () <br/>{< br/>}< br/> Public Function say (MSG: string ): string <br/> {return MSG ;}< br/> Public Function eat (): void {trace ("eat ");} <br/>}</P> <p>

 

Here, we only encapsulate a set of methods. The common practice of as3 is the math class, which is a typical example.

 

 

Third: We don't need to parse it. It contains both attributes and method classes-normal classes;

 

 

The three structures can be described from the perspective of the set. There are also some interesting class classifications from the perspective of classes.

 

That is the final class that cannot be inherited (Let's name it a lonely class ):

Dynamic attributes can be dynamically added:

There are also static classes (compared to the s文 class, personal opinion)

 

And so on.

 

 

The above are some personal opinions that must be perfect for all people, but some personal thoughts and inferences. Some personal opinions and opinions are listed below, but these structures are just classified;

 

Single Attribute Class -- only class struct containing the set of attributes

Unique Method class-only class struct containing the set of methods

Normal class-collection class struct containing attributes and Methods

Final class -- a type that cannot be inherited

Dynamic class -- classes that can dynamically add attributes

Enumeration class-the struct of a group of classes that combine finite attributes. It is a small classification of single attribute classes.

 

There are other classes that contain the class struct of other classes.

And so on.

 

 

 

 

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.