473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dependency Loop seems unavoidable

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

Aug 22 '07 #1
12 1790
On Aug 22, 12:42 am, Tim <Tian.Xiao.2...@gmail.comwrote:
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
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;
};

Aug 22 '07 #2
Tim wrote:
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 Bank
{
private:
Set<people*m_clients; //all clients
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?
There isn't one, provided you don't attempt to dereference a People*
before the full class declaration.

--
Ian Collins.
Aug 22 '07 #3
"Tim" <Ti************@gmail.comwrote in message
news:11**********************@r23g2000prd.googlegr oups.com...
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?
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.
Aug 22 '07 #4
Jim Langston wrote:
"Tim" <Ti************@gmail.comwrote in message
news:11**********************@r23g2000prd.googlegr oups.com...
>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?

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.
I think you have that the wrong way round, it is People that requires a
forward declarations.

--
Ian Collins.
Aug 22 '07 #5
Tim
On Aug 22, 1:42 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Tim" <Tian.Xiao.2...@gmail.comwrote in message

news:11**********************@r23g2000prd.googlegr oups.com...


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?

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.- Hide quoted text -

- Show quoted text -
It is easy to avoid the compilation loop. I am talking about the
design, the acyclic design.

Thanks.

Aug 22 '07 #6
Tim wrote:
It is easy to avoid the compilation loop. I am talking about the
design, the acyclic design.
Why do you want to avoid the dependency loop?

There are cases where a class even has a dependency loop with
itself. A list element is a typical example.
Aug 22 '07 #7
"Tim" <Ti************@gmail.comwrote in message
news:11**********************@r23g2000prd.googlegr oups.com...
On Aug 22, 1:42 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"Tim" <Tian.Xiao.2...@gmail.comwrote in message

news:11**********************@r23g2000prd.googleg roups.com...


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?

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.- Hide quoted text -

- Show quoted text -

It is easy to avoid the compilation loop. I am talking about the
design, the acyclic design.
Again, it depends on what you are trying to do. Are you writing code for a
bank, for people, or for the IRS?

If you are writing code for a bank, then it shouldn't be your concern what
other banks that person uses.

If you are writing code for a person, then it shouldn't be your concern what
other people that bank uses.

If you are writing code for the IRS, it would most likely be in differnet
applicatoins.

What are you trying to accomplish? What is your program intended to do? If
this is just a learning experience, then imo most times you don't need to do
such things except in experimentation.
Aug 23 '07 #8

Tim <Ti************@gmail.comwrote in message...
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; file://all clients
};

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

Any way to avoid the dependency loop?
Thanks,
Tim
<G>
Why on earth would you want to put people in a bank?
(after you get their money, you don't want them in the bank! <G>).

class Account{
std::string bankname;
std::string username;
std::string accountnumber;
long long balance; // in pennies
};

class People{
Account account;
};

class Bank{
Set<Accountclients;
public:
Account NewAccount( std::string const &name, long amount );
};

--
Bob R
POVrookie
Aug 23 '07 #9
BobR wrote:
Tim <Ti************@gmail.comwrote in message...
>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; file://all clients
};

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

Any way to avoid the dependency loop?
Thanks,
Tim

<G>
Why on earth would you want to put people in a bank?
(after you get their money, you don't want them in the bank! <G>).
He didn't put people in the bank, he put *pointers to people* in it.
You know, like an address book stored in the vault... :-)
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 23 '07 #10

Victor Bazarov <v.********@comAcast.netwrote in message...
BobR wrote:
<G>
Why on earth would you want to put people in a bank?
(after you get their money, you don't want them in the bank! <G>).

He didn't put people in the bank, he put *pointers to people* in it.
You know, like an address book stored in the vault... :-)
Or a bunch of bank employees standing around pointing at the customers. :-}
( it's not polite to point! <G>)

Hate to jump back to 'serious', but,
Set<people*m_clients; file://all clients
.... if the 'Set' was std::set, we both know there's a missing 'comparator'
in the instantiation.
IMHO, a std::vector would be a better choice for pointers. You'd still need
to write some kind of 'unique' to sort it out.

[ caution: I have not finished my first cup of coffee yet! My
single-brain-cell is only about 20% active. <G>]
--
Bob R
POVrookie
Aug 23 '07 #11
BobR wrote:
Victor Bazarov <v.********@comAcast.netwrote in message...
>BobR wrote:
>>[..]
Set<people*m_clients; file://all clients

... if the 'Set' was std::set, we both know there's a missing
'comparator' in the instantiation.
Why do you say that it's missing? There is the default compare
functor, std::less...
IMHO, a std::vector would be a better choice for pointers. You'd
still need to write some kind of 'unique' to sort it out.
8-O why bother with the vector and making it unique and sorting,
when there is std::set for it?
[ caution: I have not finished my first cup of coffee yet! My
single-brain-cell is only about 20% active. <G>]
Figures...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 23 '07 #12

Victor Bazarov <v.********@comAcast.netwrote in message...
BobR wrote:
Victor Bazarov <v.********@comAcast.netwrote in message...
BobR wrote:
[..]
Set<people*m_clients; file://all clients
... if the 'Set' was std::set, we both know there's a missing
'comparator' in the instantiation.

Why do you say that it's missing? There is the default compare
functor, std::less...
Ah, I wasn't aware that (default) std::less was smart enough to dereference
the pointer.
I'll have to read-up on that.

Person joe("Joe Smith");
Person smith("Joe Smith");
std::set<Person*clients;
clients.insert( &joe );
clients.insert( &smith );
assert( 1 == clients.size() );

?

--
Bob R
POVrookie
Aug 23 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gary | last post by:
I'm trying to install various things via fink, in particular numeric-py23. The process stops with a dependency error: dpkg: dependency problems prevent configuration of python23: python23...
33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
4
by: Evelyne | last post by:
On a server W2K, IIS5, I have many messages from ASP : cirdular dependency between types/modules. Which can be the origin of the problem? Example : Event Type: Warning Event Source: Active...
0
by: Dave Lessard | last post by:
Within my group of developers we have a list of library components we develop and continuously enhance and upgrade. We don't have source control (that's a bit of a sore issue for me) but when an...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
1
by: James Edwards | last post by:
There seems to be a bug in the link-library dependency checking in VS.NET 2003. Under the Configuration->Linker->General->Additional Library Directories property, if you specify a directory name...
5
by: Jay A. Moritz | last post by:
Error: The dependency '<my dll>' in project '<my project>' cannot be copied to the run directory because it would conflict with dependency '<my dll>'. I am getting a dependency error building...
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
3
by: donnyma | last post by:
I have a problem that looks like it has not been discussed before in these groups. I have a simple SQLAgent job that runs sp_who (could be anything, but let's just say sp_who for this example). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.