![]() |
|
#1
|
|||
|
|||
How An Object Can Create And Destroy Another ObjectI have got a problem in objects interaction. In my case I want to have a master object which will keep track of other objects .
Example: In bank and customer, I may have a class bank and class customer. In my program I want to create only one object of a type bank, under bank I will be creating objects of type customer or modifying them? How can I go about this?? Thank you |
|||
|
#2
|
||||
|
||||
Re: How An Object Can Create And Destroy Another ObjectQuote:
You probably want to use the FactoryMethod design pattern such that inside of class Bank, you have an instance of a CustomerFactory that produces your customers. While I don't agree with the "thinking" behind it, you can use the Singleton design pattern so that you have only one instance of Bank. Since the real world tells us that there are Banks and BankBranches all over the place, a Singleton of Bank doesn't make much sense to me, but that's none of my business. If you mean something else and/or do not want to use design patterns, here is a little example of how to do this in code where your Bank "manages" customers. Naturally, this example does only the minimalist amount of management. You would definitely want something more capable. CPP / C++ / C Code:
Output: Code:
...while my main function does a good bit of the management work, you could incorporate yet another class CustomerManager into your app so that Bank had/has an instance of it so that you could manage the customers through the interfaces it provides. MxB |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Click X in window won't destroy itself ? | Algar | MS Visual C++ / MFC Forum | 4 | 02-Nov-2007 12:34 |
| need help with a console menu system | BullBuchanan | C++ Forum | 6 | 20-Aug-2006 15:46 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The