Will definitely keep that in mind.
As always, a programmer faces many options on how to implement something. That’s why we have design patterns and so on… but what’s the best way to process and object and return its Element representation. I am not sure if it’s best to have a generic toElement method that takes an object, or if I should have specific toElement methods that take specific object instances. I tried to illustrate the situation:
I can do the same thing in two ways.
in my loop writing objects to Xml {
if( object instanceof ABC )
root.appendChild( ABCToElement( object) );
}
Element ABCToElement(ABC object) {
//…return element after processing
}
OR
in my loop writing objects to Xml {
root.appendChild( toElement(object) );
}
Element toElement(Object object) {
if( object instance ABCToElement)
// process element and return
}
Note that the first example could also benefit from having a toElement(Object obj) method which simply calls the appropriate method. But the different being that in the second case, there is just one big method dealing with all cases.
Are there any penaulties in heaving many methods per class? It doesn’t seem there is much problem in having a huge method with loads of if-else statements, but is it easy to mantain? I personally do not like huge methods, and tend to split it in smaller, more specific ones. But I’m not sure if much over head is indeed a problem.
I know it’s probably a silly question, but I thought why not ask since I can learn something 