473,809 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OOP/Design question

Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #1
8 1273

"codymanix" <do************ *********@gmx.d e> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

Personally, instead of having Bank hold all data for accounts, I'd break the
data down and store it in each BankAccount class. However, to answer your
question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.
--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #2
"codymanix" <do************ *********@gmx.d e> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?


Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the same,
but VERY close.
--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
---

Still waiting for ObjectSpaces? Try the EntityBroker today - more versatile,
more powerfull.
And something in use NOW. for the projects you have to deliver - NOW.
Nov 15 '05 #3
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?
Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the

same, but VERY close.

When my application is only one Assembly (which in it is in most cases),
then declaring something internal is the same as making it public.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #4
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

Personally, instead of having Bank hold all data for accounts, I'd break

the data down and store it in each BankAccount class. However, to answer your
question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount is
still public.
Ideally it would only be visible to the Bank itself. Do you think putting
the BankAccount
class into the Bank as a local class would solve that problem?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #5

"Thomas Tomiczek [MVP]" <t.********@tho na-consulting.com> wrote in message
news:OO******** ******@tk2msftn gp13.phx.gbl...
"codymanix" <do************ *********@gmx.d e> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?
Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the

same, but VERY close.

Internal restricts access to the classes in an assembly. An assembly usually
contains many classes. Friend, at least as defined in C++, restricts access
to a single class, a single member of that class, or a single non
member.

/Magnus Lidbom


Nov 15 '05 #6

"codymanix" <do************ *********@gmx.d e> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
I have a class Bank and a Class BankAccount. A Bank can contains multiple BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.
Since C# does not support friend classes, what is the best solutuion for this problem?

Personally, instead of having Bank hold all data for accounts, I'd break

the
data down and store it in each BankAccount class. However, to answer your question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount is
still public.
Ideally it would only be visible to the Bank itself. Do you think putting
the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type name is
Namespace.Bank. BankAccount now) but it should be sufficent. Just use a
private constructor(tha t is, unless my head is fooling with me today). --
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #7
> > > > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
> BankAccounts (logical, isn't it?). The central Bank object contains a > datatable which holds the data of all bankaccounts.
>
> This means, the class BankAccount must have access rights to the datatable
> in Bank, but I don't want to expose the datatable as a public property. >
> Since C# does not support friend classes, what is the best solutuion for > this problem?
>

Personally, instead of having Bank hold all data for accounts, I'd
break
the
data down and store it in each BankAccount class. However, to answer your question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount

is still public.
Ideally it would only be visible to the Bank itself. Do you think putting the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type name

is Namespace.Bank. BankAccount now) but it should be sufficent. Just use a
private constructor(tha t is, unless my head is fooling with me today).

If the ctor would be private, nobody but the BankAccount itself can
instantiate a BankAccount.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #8

"cody" <do************ *********@gmx.d e> wrote in message
news:bv******** ****@ID-176797.news.uni-berlin.de...
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
> > BankAccounts (logical, isn't it?). The central Bank object contains
a
> > datatable which holds the data of all bankaccounts.
> >
> > This means, the class BankAccount must have access rights to the
datatable
> > in Bank, but I don't want to expose the datatable as a public property.
> >
> > Since C# does not support friend classes, what is the best
solutuion
for
> > this problem?
> >
>
> Personally, instead of having Bank hold all data for accounts, I'd

break the
> data down and store it in each BankAccount class. However, to answer

your
> question as posed I'd just pass the data reference into the account
at > construction. Is it one row per account? If so then just pass the
> appropriate row into the constructor. If its multiple rows pass in a
> DataView.
This seems the best Idea to me. But the constructor of the BankAccount

is still public.
Ideally it would only be visible to the Bank itself. Do you think putting the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type

name is
Namespace.Bank. BankAccount now) but it should be sufficent. Just use a
private constructor(tha t is, unless my head is fooling with me today).

If the ctor would be private, nobody but the BankAccount itself can
instantiate a BankAccount.


Ya, I had scoping rules turned upside down, thats what happens when you try
to respond to stuff too early, ;).
In your case, you are simply going to have to be responsible with internal.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #9

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

Similar topics

5
674
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of generic design patterns that can be used and shared amongst many sub-schemas. For example, the grouping of entities. I may have the following tables: employee, product and client. These tables have no direct relationship with each other. But...
9
2942
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
2
2449
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you experts. I've been asked to create a Daily Log sheet to be distributed to some of our clerks. For each day, the clerk is to log tasks worked on for the day, (i.e worked on the johnson account).
6
2123
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
17
2728
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
17
4858
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This Page Is Valid XHTML 1.0 Transitional!" but it still wouldn't look the same. It is on http://www.dvdnowkiosks.com/new/theproduct.php scroll down and recognize the black bottom bar when you go ewith firefox(2.0) which isn't there with IE7. Why does...
6
2146
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often times when I program, I will create objects for a specific purpose for a program and if I need to add to it I just add the code.
0
2086
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the end of this message, but I will start with an overview of the problem. I've made a content management solution for my work with a decently structured relational database system. The CMS stores articles. The CMS also stores related items --...
19
3181
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design certification, possibly that involves C++, but, if not, C++ and UML. All I could find was Java + UML design certifications (one such is detailed on http://www.objectsbydesign.com/tools/certification.html). Although UML is expected to be language independent,...
8
2241
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address, port number, or both. How should we design the classes to represent these filters? My answer was: class FilterRule {
0
9602
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.