Several ways to pass values between Windows (classes) in C #!

Source: Internet
Author: User

author :peterxu source : Blog.csdn blog:http://blog.csdn.net/peterreg/
Copyright Notice : Original works, allow reprint, reprint, please be sure to hyperlink form to indicate the original publication of the article, the author's information and this statement. Otherwise, legal liability will be held. This article address: http://blog.csdn.net/peterreg/archive/2008/04/08/2259404.aspx

The transfer value between classes plays an important role in our daily programming. Various implementations have a great impact on the scalability and performance of the program.

For example: Class A's object instance is class B, an attribute A1 to access object A in object B.
    class A
        {
             private int m_ia1;
            public int A1
             {
                 get {return this.m_ia1;}
                set {this.m_ia1 = Value }
           }
        }

1. Pass object A as a parameter to Class B, that is, pass a to B in the form of a property or constructor, and then invoke A1 by reference to object A in B.
Class B
{
Private A M_oa;
Public B (a)
{
This.m_oa = A;
}
}

Class B
{
Private A M_oa;
Public B ()
{
}
Public a A
{
set {This.m_oa = value;}
}
}
Disadvantage: Class A and Class B have a high degree of coupling, and class A needs to be extended more if other classes recall the function of Class A.
Improvement:Design a unified abstract for Class A, using the interface or abstract class mode, in a certain program can reduce a certain coupling.
For the knowledge of interfaces and abstract classes, refer to my previous article, "Interfaces and abstract classes" (Interface and Abstracts Class)

2. Use intermediate file format, such as XML, text file and database, etc.
Disadvantages: Inefficient, file format needs to be unified, files need to be packaged and reconciled package
Advantages: can transmit a lot of information

3. Shared Memory space
Disadvantages: There is a certain degree of complexity, the Internet has some reference code

4. The properties of Class A are static mode
Disadvantage: This method fails when some properties cannot be set to a static property

5. The agent
disadvantage: The efficiency is slightly lower, the influence is not big
Advantages: Good encapsulation and scalability of the program

trackback:http://tb.blog.csdn.net/trackback.aspx?postid=2259404

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.