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

General design question

Hello,

This isn't specific to C#, but that is what I am using to develop my app. I
am trying to figure out how to organize my code and I'm not sure what the
best way of doing it is. For the sake of simplicity let's say I have three
classes - car, engine, and body. The car class has an instance of engine and
body.

Each class has a "build" method. The car build method calls engine.build and
body.build. I have an interface that has a visual representation of the car.
When a property is modified in the engine I call engine.build. However, I
have to pass it a reference to the car object.

I don't want to build the entire car everytime a property is modified.
Should I move the build methods into the car class? So I would have
BuildEngine and BuildBody? Or what is the best way to approach this?

Thanks for any help, I really appreciate it.

Thanks,
Nick
Feb 28 '06 #1
3 1183
Just a different way to approach the problem

1) Have an IBuildable interface, of which engine, body and all other
components implement. This could implement a Build method as well as a
Parent property.
2) Have a collection in car that maintains a dynamic list of each
component that has been added, and when the component is added to the
car, the car can set the parent (this) property to the component.
3) If you call build on an individual component, it already has a
reference to it's parent (car) and can use/notify that reference as needed.
4) If the car needs to rebuild all components, it can generically walk
through every IBuildable instance that it knows about calling the
Build() method which allows you to dynamically vary the components that
the car can contain.
But then again, I could be wrong...
Nick wrote:
Hello,

This isn't specific to C#, but that is what I am using to develop my app. I
am trying to figure out how to organize my code and I'm not sure what the
best way of doing it is. For the sake of simplicity let's say I have three
classes - car, engine, and body. The car class has an instance of engine and
body.

Each class has a "build" method. The car build method calls engine.build and
body.build. I have an interface that has a visual representation of the car.
When a property is modified in the engine I call engine.build. However, I
have to pass it a reference to the car object.

I don't want to build the entire car everytime a property is modified.
Should I move the build methods into the car class? So I would have
BuildEngine and BuildBody? Or what is the best way to approach this?

Thanks for any help, I really appreciate it.

Thanks,
Nick

Feb 28 '06 #2
Hi,

What you are looking for is basically the "Factory Pattern" where you
implement a factory class that takes care of the creation of your instances.
IVehicle vehicle = new VehicleFactory().GetVehicle(..);

I suggest that you start looking at this MSDN article to get a feel for it:
http://msdn.microsoft.com/library/de...ctopattern.asp

After that I would suggest:
http://www.martinfowler.com/articles/injection.html
http://www.springframework.net/

For the organizational part of your code (and not the creation of
objects...)...
The classes you describe are all part of your "domain" so I would put them
in the "Domain" namespace...

<Your Org/Biz name>.<App name>.Domain
Then you could have a "Business" package that takes care of the
flow/security/bla bla of your use cases...

/Oscar
"Nick" <ni********@nospam.nospam> wrote in message
news:60**********************************@microsof t.com...
Hello,

This isn't specific to C#, but that is what I am using to develop my app.
I
am trying to figure out how to organize my code and I'm not sure what the
best way of doing it is. For the sake of simplicity let's say I have three
classes - car, engine, and body. The car class has an instance of engine
and
body.

Each class has a "build" method. The car build method calls engine.build
and
body.build. I have an interface that has a visual representation of the
car.
When a property is modified in the engine I call engine.build. However, I
have to pass it a reference to the car object.

I don't want to build the entire car everytime a property is modified.
Should I move the build methods into the car class? So I would have
BuildEngine and BuildBody? Or what is the best way to approach this?

Thanks for any help, I really appreciate it.

Thanks,
Nick


Feb 28 '06 #3
What if you were to not pass the car when the engine was built but instead
enforce that relation at the creation of the engine object? You could do this
either by passing it through the constructor ..

public class Engine {
public Engine(Car _Car) {
//save the Car I belong to
}
}

you could then later push a call back out to the car if need be ...

another similar method would be to use events on the engine object that the
car object listens to for its children.

public class Car {
public void setEngine(Engine _Engine) {
//remove events from current engine
//subscribe to events on new engine
}
}

public class Engine {
public event BuildHander Build;
}

Either way in your client code you would simply say, Engine.Build() .. the
engine would then notify its parent of the building ... I personally prefer
event based example in many cases because it allows for many subscribers to
the build event but if this is a case where you are trying to hide that
information, the first may be more useful.

Cheers,

Greg

"Nick" wrote:
Hello,

This isn't specific to C#, but that is what I am using to develop my app. I
am trying to figure out how to organize my code and I'm not sure what the
best way of doing it is. For the sake of simplicity let's say I have three
classes - car, engine, and body. The car class has an instance of engine and
body.

Each class has a "build" method. The car build method calls engine.build and
body.build. I have an interface that has a visual representation of the car.
When a property is modified in the engine I call engine.build. However, I
have to pass it a reference to the car object.

I don't want to build the entire car everytime a property is modified.
Should I move the build methods into the car class? So I would have
BuildEngine and BuildBody? Or what is the best way to approach this?

Thanks for any help, I really appreciate it.

Thanks,
Nick

Feb 28 '06 #4

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

Similar topics

1
by: Steven O. | last post by:
I am basically a hobbyist programmer, at the moment doing a little work experimenting with some AI stuff. I learned C++, and then tried to teach myself MFC using MS Visual C++ 6.0. I swore off of...
2
by: kneejerkreaction | last post by:
I did not know where else to post this since there is no forum for general OOP questions. I am just getting into OOP after a lifetime of procedural programming. I'm developing a Help Desk Ticketing...
21
by: Litron | last post by:
Appologies, this isn't really a javascript specific question.... Just wondering what the current size standard is for web-page design... it used to be 800 x 600 pxls (which seems quite small...
3
by: Lauren Quantrell | last post by:
A general design question: Assuming I can figure out a way to link some local tables in an .MDB file to my Access2000 .ADP database (any help on this is appreciated as well), I'm wondering which...
3
by: JezB | last post by:
What's the generally accepted approach for using Styles and Stylesheets in a web application based on .aspx files, Web Controls, User Controls, and code-behind modules (c# in my case)? Most style...
105
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
1
by: code3_brent | last post by:
Moving from VB6 to VB.NET or C# and had a general design question... I currently have a VB6 app that functions like a wizard. Form1 is displayed with configuration settings. The user enters the...
5
by: MP | last post by:
context: vb6 / ado / adox 2.8/ mdb file format / jet 4.0 provider (not using Access) trying to design first database I work for a very small company, detailing building 'components' There is...
1
by: Tim | last post by:
Dear All, In my opinion, there are so many possible designs for a project, even small up to a class. How can I know which one is better? Is there any important point I should consider in the...
40
by: RvGrah | last post by:
I've been writing in C# for about 4 years now, coming from VB.net and VB6 before that, in which I know I'm not alone. I found learning C#, at least to the extent that I use it in developing...
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...
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
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.