Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am using the jQuery widget framework for creating some graphical elements on a webpage, and I have a conseptual question about the overall structure of the code.

I have 3 classes A, B and C which all inherits from the same parent(pABC). They are all different, but have similar functionality.

I also have to prototype classes(X, Y). These classes provide functionality that needs to be combined with A, B, C so that i get Ax, Ay, Bx, By, Cx, Cy.

I want to do this with as little duplication as possible, so that if i change something in the X prototype it automatically gets changed in all of Ax, Ay, Bx, By, Cx and Cy.

My intention is to do something like

$.widget("Ax", $.A, $.extend(true, {}, X, { ... Specific code for the Ax ... }));
$.widget("Bx", $.B, $.extend(true, {}, X, { ... Specific code for the Bx ... }));
$.widget("Cx", $.C, $.extend(true, {}, X, { ... Specific code for the Cx ... }));


$.widget("Ay", $.A, $.extend(true, {}, Y, { ... Specific code for the Ay ... }));
$.widget("By", $.B, $.extend(true, {}, Y, { ... Specific code for the By ... }));
$.widget("Cy", $.C, $.extend(true, {}, Y, { ... Specific code for the Cy ... }));

Is there a more efficient way to solve this problem? The problem is essentially that I have the classes A, B, C which is going to be combined with x, y to get Ax, Ay, Bx, By, Cx, Cy.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.