Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Before I spend time trying to do this I'd like to get a second opinion. I'm writing an application and in it I need to open a word doc in about 4 different places (as of now). So instead of writing the same code 4 times I'm thinking a class would be the way to go? I'm thinking pass the file name to the class and process as normal (all of the error handling is taken care of in the loops right now). Does this sound feasible?
Posted

Writing reusable code rather than cut & paste the same thing over and over again is a good design and what you should strive for in all your software.
 
Share this answer
 
Comments
MacRaider4 26-Apr-11 16:35pm    
That's what I figured, and using the word object in a seperate class won't cause any issues right? Just have to do all the usual declerations and what not...
NuttingCDEF 26-Apr-11 16:36pm    
Agreed - and might add some stuff in to your class to handle the Word App object intelligently so that you aren't forever starting up / shutting down Word (and killing your app's performance in the process).
MacRaider4 26-Apr-11 16:43pm    
Actually I have a lot of that already in there, thus the reason I didn't want to have it in so many locations. So far easier than I thought it would be (still getting used to using classes), only took about 5 min to implement in 2 locations.
Whether it is feasible depends on how well your code works. But in general, yes, you should not have to repeat the same code in multiple places. Even twice is too many. So extracting a class/static method that does this would certainly be an improvement.

In a UI scenario, you mght even want to have a custom control that accepts a word document path and renders it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900