"Android Source design mode"--factory method mode

Source: Internet
Author: User

NO1:

For an application, the real entrance is in the Activitythread class, and the Activitythread contains the Main method that we are familiar with. Activitythread is a final class and cannot be inherited. When the zygote process hatches a new application process, the monkey executes the Activitythread Main method, and the main method does some general logic, such as preparing Looper and message queues , It then calls Activitythread's Attach method to bind it to activitymanagerservice, starting to continuously read messages in the message queue and distribute the message.

No2:

 Public Abstract classfactory{/*** Abstract Factory method * Specific production what subclass to achieve*/     Public Abstract<textendsProduct> T createproduct (class<t>clz);} Public classConcretefactoryextendsfactory{@Override Public<textendsProduct> T createproduct (class<t>CLZ) {Product P=NULL; Try{p=(Product) class.forname (clz.getname). newinstance (); }Catch(Exception e) {e.printstacktrace (); }        return(T) p; }} Public classclient{ Public Static voidMain (string[] args) {Factory Factory=Newconcretefactory (); Product P= Factory.createproduct (CONCRETEPRODUCTB.class);    P.method (); }}

No3:

Cons: Each time we add a new product to the factory method pattern, we need to write a new product class , and also introduce the abstraction Layer , which inevitably leads to the complexity of the class structure.

"Android Source design mode"--factory method mode

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.