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.

Our system's main functionality is encapsulated in a service, let's call it X.

There are requests coming in to X-Manager service which deal with all validations and security issues, and activates X's functionality after everything passed.

We now want to extend X's functionality with a new module, let's call it Y, but without changing X's code too much, preferably without changing it at all.

Also, Y may be able to work on it's own some day (and not only extending X)

The main idea now in the team is to make X-Manager call Y with X instead of just calling X, so that Y will do it's thing and then Y Will call X's functionality instead of X-Manager.

I don't know why but this smells icky to me, I hope I managed to explain this well...

Is there any better way of doing this?

share|improve this question
    
I'm majorly confused. :) –  Steven Jeuris Jan 17 '12 at 22:42
    
How can I make my question more understandable? I've always had problems explaining these kind of things :) –  Mithir Jan 18 '12 at 6:08
add comment

1 Answer

up vote 2 down vote accepted

What you propose is a simple composition and there is absolutely nothing wrong with it. Even less since the X-Manager acts as a facade abstracting this subdivision away for the outside world. In short: this is the perfect way to do it ;)

share|improve this answer
    
OK thank you, now I can relax :) –  Mithir Jan 18 '12 at 6:07
    
I just Want to make sure... When I wrote Call Y with X, I meant passing X as a parameter to Y, so that Y will act on it and then activate X instead of X-Manager activating X, is this still ok? –  Mithir Jan 19 '12 at 10:53
    
@Mithir: Yes, there is no problem with that. If you are really sure, that you will be using the same instance of X over and over again, you can pass it to the constructor of Y, but there's no need to. Leaving it this way is very flexible. For example, you might have different instances of X (each representing a different data source for example) and the same instance of Y can operate on all of them. –  back2dos Jan 19 '12 at 11:52
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.