473,395 Members | 1,412 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,395 software developers and data experts.

OOP design question again

I have a class named Brand
Under the Brand, it may contains several exhibition, and the relationship of
Brand:Exhibition is 1:M

Then I am using this design
class Brand {
ArrayList Exhibitions;
}

But in Exhibition, do I need indicate it's Brand?
For example:
class Exhibition {
Brand brand;
}

Thanks
Sep 12 '06 #1
5 920
Wing Siu <wi******@hotmail.comwrote:
I have a class named Brand
Under the Brand, it may contains several exhibition, and the relationship of
Brand:Exhibition is 1:M

Then I am using this design
class Brand {
ArrayList Exhibitions;
}

But in Exhibition, do I need indicate it's Brand?
For example:
class Exhibition {
Brand brand;
}
That depends - do you need to be able to navigate from a Brand to an
Exhibition in your code? If you don't, it would be gneerally nicer not
to have the bidirectional link - but if it's something you need, you
can certainly do it with no problems.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 12 '06 #2
Jon Skeet [C# MVP] a écrit :
Wing Siu <wi******@hotmail.comwrote:
>I have a class named Brand
Under the Brand, it may contains several exhibition, and the relationship of
Brand:Exhibition is 1:M

Then I am using this design
class Brand {
ArrayList Exhibitions;
}

But in Exhibition, do I need indicate it's Brand?
For example:
class Exhibition {
Brand brand;
}

That depends - do you need to be able to navigate from a Brand to an
Exhibition in your code? If you don't, it would be gneerally nicer not
to have the bidirectional link - but if it's something you need, you
can certainly do it with no problems.
I have a question about this : is the Garbage Collector able to detect
(and handle) circular references ? If not (which I assume), the code
above will lead to memory "leaks".
If you create and reference a Brand in your application. Assume that
this brand has 1 Exhibition : the GC sees 1 reference to your Exhibition
(from Brand), and 2 references to your Brand (1 from the application, 1
from the Exhibition). If you free your reference to Brand in the
application, you will expect the GC to elect Brand and Exhibition, but
unfortunately there still exists one reference for each, so that they
will not be collected until the end of your application.
The solution is to use a WeakReference (see MSDN) in your Exhibition to
reference the Brand.

Mathieu
Sep 12 '06 #3
Mathieu

The GC IS able to detect cirular references and when the application
reference is released, will mark both of the objects for collection. It
starts by assuming that EVERYTHING is garbage and when he can't get a root
reference (since it's been released), will mark the objects for collection
since they are unreachable.

Still not a good idea to code it that way, but the GC WILL handle it.

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
"Mathieu Cartoixa" wrote:
Jon Skeet [C# MVP] a écrit :
Wing Siu <wi******@hotmail.comwrote:
I have a class named Brand
Under the Brand, it may contains several exhibition, and the relationship of
Brand:Exhibition is 1:M

Then I am using this design
class Brand {
ArrayList Exhibitions;
}

But in Exhibition, do I need indicate it's Brand?
For example:
class Exhibition {
Brand brand;
}
That depends - do you need to be able to navigate from a Brand to an
Exhibition in your code? If you don't, it would be gneerally nicer not
to have the bidirectional link - but if it's something you need, you
can certainly do it with no problems.

I have a question about this : is the Garbage Collector able to detect
(and handle) circular references ? If not (which I assume), the code
above will lead to memory "leaks".
If you create and reference a Brand in your application. Assume that
this brand has 1 Exhibition : the GC sees 1 reference to your Exhibition
(from Brand), and 2 references to your Brand (1 from the application, 1
from the Exhibition). If you free your reference to Brand in the
application, you will expect the GC to elect Brand and Exhibition, but
unfortunately there still exists one reference for each, so that they
will not be collected until the end of your application.
The solution is to use a WeakReference (see MSDN) in your Exhibition to
reference the Brand.

Mathieu
Sep 12 '06 #4
"WhiteWizard" <Wh*********@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
Mathieu

The GC IS able to detect cirular references and when the application
reference is released, will mark both of the objects for collection. It
starts by assuming that EVERYTHING is garbage and when he can't get a root
reference (since it's been released), will mark the objects for collection
since they are unreachable.

Still not a good idea to code it that way, but the GC WILL handle it.
Why do you say it's not a good idea to code it that way? If you potentially
need to navigate from an Exhibition to a Brand and vice versa?

Kind Regards,
Allan Ebdrup
Sep 12 '06 #5
Wing Siu wrote:
I have a class named Brand
Under the Brand, it may contains several exhibition, and the relationship of
Brand:Exhibition is 1:M

Then I am using this design
class Brand {
ArrayList Exhibitions;
}

But in Exhibition, do I need indicate it's Brand?
For example:
class Exhibition {
Brand brand;
}
You look in your UML class diagram and see if there are arrows
only one way or both ways.

:-)

Arne
Sep 12 '06 #6

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

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
10
by: BlueDolphin | last post by:
I'm not sure if this is a question or more of a rant... but I'm looking for some input on this from other developers out there. How often has the following happened to you and how have you dealt...
10
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post...
0
by: Ziyad Makki | last post by:
Hello, I have created a Web Composite Control. I have also created a designer class that is used to render the control at design time. All though it dose work, I have been experiencing some...
17
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...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
5
by: A_M_IS | last post by:
Dear valuable experts, I truly hope than You can suggest for me Your ideas how to resolve design. I developing relative small Access VB tool, for single user use only. Access version 2003, but db...
17
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...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...

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.