Introduction to one of the Java basics objects

Source: Internet
Author: User
Tags export class

Introduction to Objects 1.1 abstract process

All programming languages provide an abstraction mechanism. The complexity of the problems that people can solve depends directly on the type and quality of the abstraction.
Assembly language is a slight abstraction of the underlying machine.
We refer to the elements in the problem space and the representations in their re-interpretation spaces as objects . The idea is that a program can make itself available to a particular problem by adding new types of objects .

    • All things are objects
      You can extract any conceptualization of the problem you are solving to build an object in the presentation program.
    • A program is a collection of objects
      They tell each other what they want to do by sending a message.
    • Each object has its own storage that is made up of other objects
    • Each object has its type
    • All objects of a particular type can receive the same message
1.2 Each object has an interface

Creating abstract data types (classes) is one of the basic concepts of object-oriented programming.
You can create a variable of a certain type, and then manipulate those variables.
Class describes a collection of objects that have the same attributes (data elements) and behaviors (functions), so a class is actually a data type.

1.3 Service for each object

Each object provides services that help improve the cohesion of the object. High cohesion is one of the basic quality requirements for software design: This means that the various aspects of a software component are well-combined.

1.4 Concrete implementations that are hidden

Divide program developers into class creators and client programmers by role.
The goal of the client programmer is to collect a variety of classes for rapid application development. The goal of the class creator is to build the class, which exposes only the necessary parts to the client programmer and hides the other parts.
Access control: A reason why the client programmer cannot reach the part that should not be touched. Another reason for this is that it allows library designers to change the way they work inside a class without worrying about affecting the client programmer.

1.5 Multiplexing specific implementations

The new class is synthesized using an existing class, which is called a combination .
If the combinations are dynamic, they are usually called aggregates .

1.6 Inheritance

When the parent class changes, the modified subclass also changes.
When an existing type is inherited, a new type is created.
The export class and base class have the same type.
If you simply inherit a class without doing anything else, the methods in the base class interface will inherit directly from the exported class.

1.6.1 is a relationship with like a

Export classes and base classes exactly the same type, because they have exactly the same interface. You can use an export class object to completely replace a base class object. This can be considered a purely alternative, often referred to as an alternative principle . Is-a relationship
It is sometimes necessary to add new interface elements to the export type, which expands the interface. This new type can be substituted for the base class, but this substitution is imperfect, because the base class cannot access the newly added method. Can be described as is-like-a relationships.

1.7 Interchangeable objects associated with polymorphism

When dealing with a hierarchy of types, you want to treat an object as a base class instead of treating it as the object type it represents.
One of the basic ways to encapsulate changes by exporting new subtypes and easily extending the capabilities of the design.

1.8 Single-Root inheritance structure

All objects in a single inheritance structure have a common interface, all of which are the same basic types in the final analysis.
A single inheritance ensures that all objects have some functionality.
A single inheritance structure enables the garbage collector to have some functionality. Because all objects are guaranteed to have their type information, there is no deadlock in the inability to determine the type of the object.

1.9 Containers

In C + +, a container is called the Standard template class library.
The single container is not enough to meet the existing needs, but also to be easy to choose, the main reason is two:

    • Different containers provide different types of interfaces and external behavior.
    • Different containers have different efficiencies for some operations
1.9.1 Parameterized types

A parameterized type is a class that the compiler can automatically customize to act on a particular type. In Java, it is called generics.

1.10 creation and lifetime of objects

One of the most critical issues when working with objects is their generation and destruction. Each object needs resources, especially memory, in order to survive. When we are not in need of objects, we need to clean up the resources we occupy.
There are two ways in which the data for an object exists:

    • To maximize execution speed, the object's storage space and life cycle can be determined at the time of programming, which can be achieved by placing the object on a stack or domain-limited variable or static store. This approach places the allocation and deallocation of storage spaces in a preferred position.
    • Dynamically create objects in the pool of memory in the atoll. In this way, it is not until the runtime knows how many objects are needed, what their life cycles are, and what their specific types are. Because storage space is managed dynamically, all of the time it takes to allocate space in a heap, which may be much larger than creating space in the stack. This is how Java is used.
1.11 Exception Handling: Handling Errors

An exception is an object that is "thrown" from the wrong place and is specifically used to handle the corresponding exception handler "capture" of a particular type of error. Exception handling is like another path that is executed in parallel with the normal program execution path when the error occurs.
Exceptions provide a way to reliably recover from an error condition.

1.12 Concurrent Programming

Sometimes interrupts are necessary for processing a time-intensive program, but for a number of other problems, we only want to split the problem into separate parts for execution. In the program, these parts that run independently of each other are called "threads", a concept called concurrency .
Concurrency may seem quite useful, but there is a hidden danger: sharing resources. If multiple parallel tasks have access to the same resource, a problem occurs.
Workaround: When a task accesses a resource, it locks the resource until it is finished, releasing the resource and using it for other tasks.

Introduction to one of the Java basics objects

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.