5

For example, suppose I had a pageControl UI class and a searcher business logic class with the following :

pageControl.js

function searchButtonClicked() {
  // call business logic class method when button clicked
  searcher.beginSearch();
}

function showSearchResultsPage(searchResults) {
  // when this is called, display results
  ui.loadContent(searchResults);
}

searcher.js

// This module has a low to moderate chance of someday being used on two or more different pages.
function beginSearch() { ... }

function searchCompleted(results) {
  // This here is what I view as the main problem
  pageControl.showSearchResultsPage(results);
}

The problem is that searcher is specifically tied to pageControl, and it's making the decision that the search result page will be the next thing to appear. The example I was going to give to people about why this is bad gives the idea that "You wouldn't directly conditionally call the logic for your entire app inside of Button>onClick", but I'm trying to find a more comprehensive argument about why that is.

At first I thought this was "inversion of control" but looking that up on Wikipedia didn't portray it as negatively, so I don't think that's the right term for this kind of pattern.

Is there a name for this anti-pattern of having low-level components controlling higher-level ones?

  • 13
    It's called the "not everything has to have a name" pattern. – Robert Harvey Jun 3 '15 at 15:10
  • 2
    "some things are just bad" – user40980 Jun 3 '15 at 15:11
  • 3
    That's simply high coupling. And between distant layers and in the wrong direction, too. – Kilian Foth Jun 3 '15 at 15:16
  • 2
    @Katana314 the reason for the down-votes is simply that it isn't on topic for the site. As to why the questions is not well formed; it contains the presumption that the code contains a specific anti-pattern of which you don't know the name of. Maybe it is an antipattern maybe it isnt - that is likely subjective. – Dave Hillier Jun 3 '15 at 16:04
  • 3
    layering violation. – Javier Jun 4 '15 at 14:59
3

It is called an inversion of authority, named so by Ed Yourdon if memory serves. An example of the usage can be found here.

1

Circular Dependency

If we view pageControl.js as your UI layer, a controller perhaps, and searcher.js as you data access and or business layer, a circular dependency has been introduced that effectively makes them inseparable and defeats any benefits of layering.

Arguments could also be made for spaghetti code and accidental complexity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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