Structuring classes with similar properties

Knud Soerensen 4tuu4k002 at sneakemail.com
Sat Mar 3 14:56:37 PST 2007


On Sat, 03 Mar 2007 14:02:07 -0500, Nathan Petrelli wrote:

> I didn't knew where to post this questions, please excuse me if this isn't the right group.
> 
I think digitalmars.D.learn would be better.

> I'm having problems organizing the code of my application because I have several similar classes but some of them lacks some properties and others introduce new properties. Right now they all have lots and lots of duplicated code and it's started to hurt development:
> 
First notice that your classes contain an abstract class I would call a
ClientServiceRequest.

class ClientServiceRequest
{
	int id;
	char[] clientName;
 	real total;
	Details[] details;

string print() {
 		printer.appendCenter("%s", toString(getUTCTime()));
 		printpart1(printer); // must be implemented in the child class
                printer.append("Client: %s", clientName);
 		printpart2(printer); // must be implemented in the child class
 		foreach (Details det; details)
 			printer.append("%s %s %s %s", det.product, det.ammount, det.price);
 		printer.append("Total: %s", total);
 		printer.print();
 	}
}



More information about the Digitalmars-d mailing list