this might be more of a general programming question but since i use c# i figure i will post it here.
when making class libraries what considerations should i keep in mind? i am going to make my own xml processing library for use in my own programs and am wondering what i should keep in mind when doing so.
i know there is already an xml namespace but i noticed i write alot of classes the same for multiple programs, mainly reading nodes and id like to just make one file i can go to when i need the same methods rather than rewriting them changing small details for each program.
would it be better to just make a single class file and use that or will the .dll be a better approach?
class library considerations
Page 1 of 12 Replies - 388 Views - Last Post: 15 February 2011 - 02:44 PM
Replies To: class library considerations
#2
Re: class library considerations
Posted 15 February 2011 - 01:48 PM
Well, with a library you have more room for additions and future develoment if you come up with new ideas in the future. Ask yourself what your general structure is. If you have nothing else separated into libraries then it will probably be more annoying than usefull, but if you are serious about your XML handling then a separate DLL sounds like a good idea.
With your own DLL you can also add business objects that are specific to your XML handling without confusing their use.
With your own DLL you can also add business objects that are specific to your XML handling without confusing their use.
#3
Re: class library considerations
Posted 15 February 2011 - 02:44 PM
As someone who has been there before here are a couple of hints:
- Use Interfaces
- If adding functionality, overload rather than modify your methods
Interfaces (and Factories) make it really easy for you to extend your code, either within a single project or within your class library. Even if you think you won't ever change your code I can almost guarantee that within 6 months to a year you will, and having a bunch of pre-defined interfaces will make life so much easier.
Overloading methods means you won't break old projects relying on previous methods, depending how long your library sticks around you can even get into trouble changing code inside a method so it produces a slightly different output. I've run into problems with changing the guts of a method only to find that some old, forgotten project expected something very specific that is no longer there (or in the right order). A right pain when that old project happens to be a crucial piece of someone else's framework. If you need to change what a method does the best way I found was to create a new class that extends the original, then do an override on the method you want to change. That way you can use the new class from then on and forget about the old one which will hang around to support older code bases.
If you think you will want to add stuff besides XML-related code later (like maybe a class for maintaining a buffer of data files for processing fed by multiple threads) then name your class library something more generic so it more accurately describes what's inside, ie "*your initials*Lib", then use different namespaces inside to separate your classes. For instance, JSLib.XML for XML stuff, JSLib.Data for data managers etc.
- Use Interfaces
- If adding functionality, overload rather than modify your methods
Interfaces (and Factories) make it really easy for you to extend your code, either within a single project or within your class library. Even if you think you won't ever change your code I can almost guarantee that within 6 months to a year you will, and having a bunch of pre-defined interfaces will make life so much easier.
Overloading methods means you won't break old projects relying on previous methods, depending how long your library sticks around you can even get into trouble changing code inside a method so it produces a slightly different output. I've run into problems with changing the guts of a method only to find that some old, forgotten project expected something very specific that is no longer there (or in the right order). A right pain when that old project happens to be a crucial piece of someone else's framework. If you need to change what a method does the best way I found was to create a new class that extends the original, then do an override on the method you want to change. That way you can use the new class from then on and forget about the old one which will hang around to support older code bases.
If you think you will want to add stuff besides XML-related code later (like maybe a class for maintaining a buffer of data files for processing fed by multiple threads) then name your class library something more generic so it more accurately describes what's inside, ie "*your initials*Lib", then use different namespaces inside to separate your classes. For instance, JSLib.XML for XML stuff, JSLib.Data for data managers etc.
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote








|