concept new package in category software development

appears as: new package, new packages
The Mikado Method

This is an excerpt from Manning's book The Mikado Method.

Granted, if this is the only code you’ll ever need, it’s probably fine. But it’s rarely this simple. The CylinderLock depends on a lot of code that’s specific to the CylinderLock, and the Door transiently depends on that code as well, as the left part of figure 6.5 shows. Now, if you want to move the Door to a new package, you’ll have to make sure that the entire tail of dependencies from CylinderLock is also reachable. This could be OK, but it’s often a problem when restructuring code.

A common Mikado scenario is extracting a piece of code from such a codebase to create a library that can be used in several places. In the following sections, you’ll see a few powerful ways to move code around, remove code, or put parts of your code into new packages.

You need to regroup scattered code into a new package, but for some reason you can’t merge the code before splitting out the new package, as in the merge-reorganize-split pattern.

Create a new package that all concerned packages depend on, and move the scattered code directly to the new package, as shown in figure 7.8.

Figure 7.8. Move code directly to a new package: 1) The initial situation with scattered code in several packages. 2) Create a new package for the scattered code. 3) Move the scattered code into the new package, starting with the package with the least number of outgoing dependencies. 4) The result with all scattered code gathered in one package.

As you can see in the figure, you start out with packages that have scattered code (1). Then you create the new empty package and add that package as a dependency for the other packages (2). Next, you move the scattered code from the package with the least number of outgoing dependencies first, which in this example is package C, and then in turn B and A (3). By doing so, the risk of breaking dependencies by moving code is minimized, although not eliminated. You end up with the scattered code gathered in the new package (4).