"Android Source design mode"-prototype mode

Source: Internet
Author: User

NO1:

Prototype mode usage Scenarios :

1) class initialization consumes a lot of resources, including data, hardware resources, and so on, through prototype replication to avoid these consumption

2) Creating an object through new requires very tedious data preparation access, which can be used in prototype mode

3) When an object needs to be provided to other object access, and each caller may need to modify its value, consider using prototype mode to copy multiple objects for the caller to use, that is, a protective copy

No2:

Most of the prototype pattern is implemented by implementing the Cloneable interface , but the constructor is not executed when the object is copied through clone.

No3:

Cloneable is an identity interface in which the Clone method is not the Cloneable interface, but the method in object.

No4:

A shallow copy does not actually reconstruct all the fields of the original document, but rather the fields of the copy document refer to the fields of the original document, and the solution is to use a deep copy

NO5:

ArrayList implements the Cloneable interface, which belongs to the prototype mode

NO6:

The cloning method inside the Intent is done through the new Intent (this) constructor . Because the Clone () function is used to achieve high efficiency only when the object's construction cost is higher or the construction is more cumbersome

No7:

After the packagemanagerservice(PMS) is started, it scans the installed APK directory on the system, The PMS will parse the Androidmanifest.xml file under the APK package to get information about the app and build the entire information tree of the APK after completion. The PMS's parsing work on the APK has started when it was constructed.

No8:

The PMS not only needs to load the various types of apk that the system has installed, but it also needs to load the framework resources and core libraries before starting to parse the APK file in the scanned directory after loading the resource and core library.

No9:

startactivity is finally called Startactivityforresult

No10:

Packagemanagerservice starts when the system starts, and the PMS resolves information about all installed apps, builds an information table, and when the user jumps to a component through intent , The corresponding component list is found in the PMS based on the information contained in the intent, and finally jumps to the target component.

NO11:

One of the most important uses of prototype mode is a protective copy , which means that an object may be read-only, and in order to prevent external modifications to this read-only object, it is often possible to implement a read-only restriction by returning a copy of the object.

No12:

Advantages :

The prototype pattern is a copy of the binary stream in memory, which is much better than the direct new one, especially when generating a large number of objects in a loop.

Disadvantages :

It is both an advantage and a disadvantage to copy directly in memory and the constructor will not execute. The advantage is that the constraint is reduced, and the disadvantage is reduced.

"Android Source design mode"-prototype mode

Related Article

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.