Centralized and decentralized decision-making (2)

Source: Internet
Author: User

Decentralized decision-making is the opposite of centralized decision-making. The following code is written based on the idea of decentralized decision-making.

Class P2
{
Private:
Int m_nVal;
Public:
Int fun (int nVal1, int nVal2, int nVal3) const
{
If (m_nVal <60)
Return nVal1;
Else if (m_nVal = 60)
Return nVal2;
Else if (m_nVal> 60)
Return nVal3;
Return-1;
}
};

Class P1
{
Private:
Int m_nVal;
Public:
Int fun (const P2 & aP2) const
{
If (m_nVal <60)
Return aP2.fun (0, 1, 2 );
Else if (m_nVal = 60)
Return aP2.fun (3, 4, 5 );
Else if (m_nVal> 60)
Return aP2.fun (6, 7, 8 );
Return-1;
}
}; Www.2cto.com

Int fun (const P1 & aP1, const P2 & aP2)
{
Return aP1.fun (aP2 );
}

The if-else judgment in the original fun function is moved to the inside of the class, which is the object-oriented method. Each class is responsible for its internal data and makes decisions accordingly.

From acloudhuang's column

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.