Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know the idea of strong cohesion applies to methods as much it applies to classes. Just to be clear when I say strong cohesion of a method I mean a method which does only one task and does it well. This idea really works for simple getters and setters. But sometimes we usually come across methods that does more than one task internally , although it seems to be doing a single task if you look at a higher level of abstraction. An example of such a method can be :

 public void startUp() {
        List<SubSystem> subSystems = getSubSystems();
        sychronized(subSystems) {
            for (SubSystem subSystem : subSystems) {

And inside those subSystem#initialize() methods a lot is going on. So is this a violation of the high/strong cohesion principle ?

share|improve this question
up vote 4 down vote accepted

No. It looks like it's a cohesive method. You might rename the method "initializeAllSubsystemsOnStartup" and that's probably more descriptive than "startUp". Here's a non-cohesive example:

public void updateCustomerOrders(Customer customer, Orders newOrders) {
    if(!customer.isPersisted()) {; }
    else if(customer.inGoodStanding() { 
        for(Order order in Orders) { order.setCustomer(); }; 
    } else {
        updateUi("Invalid customer");

It's not cohesive because the method claims to be about updating customer orders (the lines in the else if block, but does many things, including possibly updating the UI which doesn't feel like it should a concern at this layer.

share|improve this answer

Your Answer


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.