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

architect question

Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ]
Option 2: Have A create an instance of B.

other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to decouple or reduce the dependency ?

I went to a seminar and heard of how when a class gets created it gets created with the right object types... say like a Tax object tailored for the US vice Canada. Thanks for the advice. Andrew
Nov 15 '05 #1
7 1255
Without a full understanding of your problem, it is difficult to provide a
correct architectural analysis, but here are some things to keep in mind.

Both O1 and O2 sound good and are really not much different. The choice
between the two may lie in whether you want to reuse the same object B on
more then one object A. In that case O1 would save some memory. This is an
effective way to decouple the objects so you may be on the right path.

From your last paragraph, it sound like you are talking about the strategy
design pattern
(http://www.exciton.cs.rice.edu/JavaR...trategyPattern
..htm).

Hope this hellps with the limited information.

"andrewcw" <an******@acw.com> wrote in message
news:E0**********************************@microsof t.com...
Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ] Option 2: Have A create an instance of B.

other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to decouple or reduce the dependency
?
I went to a seminar and heard of how when a class gets created it gets

created with the right object types... say like a Tax object tailored for
the US vice Canada. Thanks for the advice. Andrew
Nov 15 '05 #2
"andrewcw" <an******@acw.com> wrote in message
news:E0**********************************@microsof t.com...
Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ]

If B is a value type, the instance is copied when you pass it to a method,
which is an extra object in memory. If A just creates an instance of B and
another instance of B didn't exist in the first place, then there is no
difference.

If B is a reference type, a copy of the reference would be passed, resulting
in no significant difference in memory use.
Option 2: Have A create an instance of B.
Your choice of whether to pick Option 1 or Option 2 depends on the
relationship between A and B. If B depends on the lifetime of A, then use
Option 2. However, if B has an independent lifetime, then Option 1 would be
better.
other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to decouple or reduce the dependency
?

Make B implement an interface and define any parameters or variables to be
of the interface type. This will allow you to pass different types that
implement that interface.
I went to a seminar and heard of how when a class gets created it gets

created with the right object types... say like a Tax object tailored for
the US vice Canada.

Check out the docs on Localization and Resources, which .NET supports.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #3
Andrew... As Joe Mayo has stated, if the lifetime of B is dependent on
A,
then use composition aka containment by ownership. If you are simply
wrapping B to adapt the interface to A use containment by reference.
Modeling forces you to think about these things <g>.

http://www.geocities.com/jeff_louie/OOP/oop12.htm

Regards,
Jeff
Option 1: instantiate A by passing in an instance of B [ I think this

is
less memory than option 2 ]
Option 2: Have A create an instance of B.<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
First of all, I wouldnt say this is an architectural question. It is merely
a design decision based on forces. In both situations your memory impact is
completely dependant on whether the instance of B is associated to many
other instances of A at the same time. If your situation is simply that you
need an A, and it needs a B and one is created and passed in, you will
clearly get a memory impact - but if that is the true domain, then that is
the true domain.

Option 2 is a design choice one would make early on while the system is
taking shape. However this violates a few fundamental principles of object
orientation, in that you will clearly need to recompile the whole system if
you need A to now use a C instead of a B, but C decends from B. Option 2
violates a principle pioneered by Bertrand Meyer many moons ago, known as
the Open Closed Principle: "A module should be open to extension, but
closed for modification". In laymen terms, you should be able to extend A's
use with other neighbouring objects without requiring the need to change
your code in class A (the modification aspect). Depending on abstract types
is the key.

The most advanced technique for decoupling is using interfaces, and
inverting the dependancy. A then has a dependancy on an interface that is
contextually part of A's micro-problem domain. For example a Swtich could
depend on ISwitchable. Then, any bunch of objects could implement
ISwitchable, and Switch can now be extended to talk to a whole suite of
classes withouth making a single change to Switch.

Based on this, the whole reason for creating objects with the right types is
because a policy layer makes the decisions at application start up or
runtime (using factories). As an example, you might have a business object
that depends on a dal object. For arguments sake A might need persisting by
IADataService. At some point a decision is made whether to use the RDBMS
IADataService, the XML IADataService or some other data service
implementation. This decision is then applied as a policy, to the
instantiation of the association between A and its IADataService. If you
didnt create the objects passing in its types in this manner, the system
wouldnt be extendable.

HTH

Nick.

"andrewcw" <an******@acw.com> wrote in message
news:E0**********************************@microsof t.com...
Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ] Option 2: Have A create an instance of B.

other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to decouple or reduce the dependency
?
I went to a seminar and heard of how when a class gets created it gets

created with the right object types... say like a Tax object tailored for
the US vice Canada. Thanks for the advice. Andrew
Nov 15 '05 #5
Hello Andrew,

You've taken a basic course in Design Patterns, from the looks of it. I
suggest that you investigate some of the patterns more thoroughly. The
information you provide is insufficient to make a good choice between your
two options, or a potential third or fourth option. Other folks have
provided some good advice, and I hope that helps.

Note: memory is not the point. Maintainability, readability,
extensability... these are nearly always far more important than a few bytes
of RAM. Using published Design Patterns will give you both.

Good Luck,
--- Nick M.

"andrewcw" <an******@acw.com> wrote in message
news:E0**********************************@microsof t.com...
Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ] Option 2: Have A create an instance of B.

other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to decouple or reduce the dependency
?
I went to a seminar and heard of how when a class gets created it gets

created with the right object types... say like a Tax object tailored for
the US vice Canada. Thanks for the advice. Andrew
Nov 15 '05 #6
Thanks for your views - I really appreciate you comments
and yes I was thinking of factory patterns...
-----Original Message-----
Can someone share some insight on this:

I have a class A. It needs functions from class B.

Option 1: instantiate A by passing in an instance of B [ I think this is less memory than option 2 ]Option 2: Have A create an instance of B.

other ideas - some form of interface, but then some place I still have an instance of B. What are some good ways to
decouple or reduce the dependency ?
I went to a seminar and heard of how when a class gets created it gets created with the right object types... say
like a Tax object tailored for the US vice Canada. Thanks
for the advice. Andrew.

Nov 15 '05 #7

Hi andrewcw,

Thanks for your feedback.

I am glad the community's reply makes sense to you.

If you have any further concern, please feel free to tell me, I will work
with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #8

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

Similar topics

2
by: Stefan Svensson | last post by:
I posted this request for help in Visio, troubleshooting newsgroup and Installation newsgroup, about 1,5 months ago but without result. "I recently installed Visio .NET Enterprise Architect 2003...
2
by: Vick | last post by:
Hi Folks, I'm not too sure if this is the appropriate place to ask this question, but I'm trying to figure out what some of the main differences between the following Job roles are on an IT...
5
by: | last post by:
Hello, I bought Visual Studio 6.0 Professional several years ago as a college student with the academic price/license. Microsoft's Upgrade Eligability page (http://tinyurl.com/3mtga) does list...
1
by: xman | last post by:
very hard is fix exactly group for this question.. but I am sure that some of people here have some experience with these compilers: Visual Studio NET Enterprise Architect 2002 and Visual Studio...
3
by: george r smith | last post by:
What are the main advantages to a developer in purchasing Visual Studio .NET Enterprise Architect over Visual Studio .NET Developer. I know of the web sites - just would like some developer...
17
by: Big Charles | last post by:
Hello, Recently, a friend of mine has told me that he is a .NET System Architect. What is a .NET System Architect? What are their functions? What is the difference between an Architect and a...
4
by: Arlene Reid | last post by:
Hi all I need to use enterprise architect to create class diagrams with all their various atrributes and relationship. I then need to generate xml from this class diagram. Has anyone tried doing...
1
by: Subhendu | last post by:
I am Subhendu...I m an consultant ... We have an argent requirements with One of our client for Chief Architect(Sr Director) Position. Post :Chief Architect(Sr Director) Reporting to: CTO ...
0
by: sam | last post by:
Hi, Hope you are doing well !!!! One of our clients is looking to augment their team with “Database Architect – DB2" please find below the details and respond with
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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...

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.