依赖循环似乎是不可避免的 [英] Dependency Loop seems unavoidable

查看:74
本文介绍了依赖循环似乎是不可避免的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,


依赖性不应该是循环的。但是,我认为这是不可避免的。对于

的例子,我有两个类:Bank和People如下


class Bank

{

private:

Set< people * m_clients; //所有客户

};


类人物

{

私人:

银行* m_bank; //在哪个帐户被打开。

};


有什么方法可以避免依赖循环?


谢谢,


Tim

Dear All,

Dependency should be not looped. However, I think it unavoidable. For
example, I have two classes: Bank and People as follows

class Bank
{
private:
Set<people*m_clients; //all clients
};

class People
{
private:
Bank* m_bank; // in which an account is opened.
};

Any way to avoid the dependency loop?

Thanks,

Tim

推荐答案

8月22日上午12:42, Tim< Tian.Xiao.2 ... @ gmail.comwrote:
On Aug 22, 12:42 am, Tim <Tian.Xiao.2...@gmail.comwrote:

亲爱的所有人,


依赖应该是没有循环但是,我认为这是不可避免的。对于

的例子,我有两个类:Bank和People如下


class Bank

{

private:

Set< people * m_clients; //所有客户


};


类人物

{

私人:

银行* m_bank; //在哪个帐户被打开。


};


有什么方法可以避免依赖循环?


谢谢,


Tim
Dear All,

Dependency should be not looped. However, I think it unavoidable. For
example, I have two classes: Bank and People as follows

class Bank
{
private:
Set<people*m_clients; //all clients

};

class People
{
private:
Bank* m_bank; // in which an account is opened.

};

Any way to avoid the dependency loop?

Thanks,

Tim



您可以尝试重新思考现实世界对象的映射到

班;所有银行都有客户,但不是所有人都有银行吗?


类人员{

//姓名,地址等

};


班级银行{

public:

class客户:公共人员{

银行* m_bank;

//一组银行帐号,其他客户特定的

不是所有人都有的东西

};


std :: set< Client * m_clients;

};

You could try rethinking your mapping of real-world objects to
classes; all banks have clients, but not all people have banks?

class Person {
// name, address, etc
};

class Bank {
public:
class Client : public Person {
Bank* m_bank;
// A set of bank account numbers, other client-specific
things that not all people have
};

std::set<Client*m_clients;
};


Tim写道:
Tim wrote:

亲爱的所有人,


依赖性不应该是循环的。但是,我认为这是不可避免的。对于

示例,我有两个类:Bank和People如下
Dear All,

Dependency should be not looped. However, I think it unavoidable. For
example, I have two classes: Bank and People as follows



class People;

class People;


类银行

{

私人:

设置< people * m_clients; //所有客户
class Bank
{
private:
Set<people*m_clients; //all clients



Set< People * m_clients; //所有客户

Set<People*m_clients; //all clients


};


class人物

{

私人:

银行* m_bank; //在哪个帐户被打开。

};


有什么方法可以避免依赖循环?
};

class People
{
private:
Bank* m_bank; // in which an account is opened.
};

Any way to avoid the dependency loop?



如果你没有尝试在全班宣布之前解雇一个人*

,那就没有一个。


-

Ian Collins。

There isn''t one, provided you don''t attempt to dereference a People*
before the full class declaration.

--
Ian Collins.


" Tim" < Ti ************ @ gmail.com写信息

新闻:11 ****************** ****@r23g2000prd.googlegr oups.com ...
"Tim" <Ti************@gmail.comwrote in message
news:11**********************@r23g2000prd.googlegr oups.com...

亲爱的所有人,


依赖性不应该是循环的。但是,我认为这是不可避免的。对于

的例子,我有两个类:Bank和People如下


class Bank

{

private:

Set< people * m_clients; //所有客户

};


类人物

{

私人:

银行* m_bank; //在哪个帐户被打开。

};


有什么方法可以避免依赖循环?
Dear All,

Dependency should be not looped. However, I think it unavoidable. For
example, I have two classes: Bank and People as follows

class Bank
{
private:
Set<people*m_clients; //all clients
};

class People
{
private:
Bank* m_bank; // in which an account is opened.
};

Any way to avoid the dependency loop?



好​​吧,因为People里面的Bank *是一个指针,所以它只需要
编译就可以了

class Bank;

声明。它不需要看到银行的互通,除非你的b $ b试图在People类中取消它。如果人们只是简单地返回指向某个东西的指针,那么你没有问题。


还要考虑一些人使用多个银行。这取决于你试图做什么


Well, since Bank* inside People is a pointer, the only thing it needs to
compile is a
class Bank;
declaration. It does not need to see the interworkings of Bank unless you
attempt to derefernce it inside of the People class. If People simply
returns the pointer to something, then you have no problem.

Consider, also, that some people use more than one Bank. It depends on what
you are attempting to do.


这篇关于依赖循环似乎是不可避免的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆