Too much duplication

R

Rob Richardson

Greetings!

I am trying to split pieces of code out from my company's application into
components that can easily be reused. I've run across a couple of places
where I think I have to do more than I should.

Case 1: I have three classes: Top, Middle (derived from Top) and Bottom
(derived from Middle). The definitions for all three are in separate DLLs.
When I built the Bottom project, I added a reference to the Middle project.
I got an error saying that since Middle references Top, Bottom also had to
reference Top. I don't understand this. Why should Bottom know anything
about Top? It will never use anything in Top directly. This seems also to
mean that if a user ever uses the Bottom class,. his project would have to
reference all three DLLs! Isn't there a way I can make it sufficient for
Bottom to reference Middle?

Case 2: My components should work on both Pocket PCs and desktops wherever
possible. I haven't yet found a way to have a single project with two
configurations, one for desktop builds and the other for Pocket PC builds.
But that's not the point of this question. I have two projects, one for
each target. There is no difference in the source code between the two
projects. But if I select Add Existing Item and add a class file used in
one project to the other project, the file gets copied into the second
project's folder. Isn't there a way for two projects to use the same file?

Thanks very much!

Rob Richardson
 
J

Jon Skeet [C# MVP]

Rob Richardson said:
I am trying to split pieces of code out from my company's application into
components that can easily be reused. I've run across a couple of places
where I think I have to do more than I should.

Case 1: I have three classes: Top, Middle (derived from Top) and Bottom
(derived from Middle). The definitions for all three are in separate DLLs.
When I built the Bottom project, I added a reference to the Middle project.
I got an error saying that since Middle references Top, Bottom also had to
reference Top. I don't understand this. Why should Bottom know anything
about Top? It will never use anything in Top directly. This seems also to
mean that if a user ever uses the Bottom class,. his project would have to
reference all three DLLs! Isn't there a way I can make it sufficient for
Bottom to reference Middle?

No. If Middle derives from Top, then Bottom needs to know about Top -
otherwise how would it know what members Middle has inherited from Top?
Case 2: My components should work on both Pocket PCs and desktops wherever
possible. I haven't yet found a way to have a single project with two
configurations, one for desktop builds and the other for Pocket PC builds.

Build for Pocket PC, and it'll work on the desktop too.
But that's not the point of this question. I have two projects, one for
each target. There is no difference in the source code between the two
projects. But if I select Add Existing Item and add a class file used in
one project to the other project, the file gets copied into the second
project's folder. Isn't there a way for two projects to use the same file?

You can add it in a different way somehow, but I can't remember how
offhand. However, that's not the way to go - building it just as a
Compact Framework project is the way to go.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top