Over a million developers have joined DZone.

Principles of Containment

DZone's Guide to

Principles of Containment

There are many types of containers and challenges surrounding their usage. Dependency injection, VMs, Docker-types, and UIs all help contain aspects of their own environments.

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

Claim: The thing doing the containing can see the thing it is containing. The latter really only suspects it is contained, and can’t casually reach back to the container, unless the container configured it to do so.

We're going to dive into an overview of container architecture and four various styles of containers, how they're used, and their limitations.

Dependency Injection

With friends, I wrote PicoContainer in 2003. It was the first constructor injection container for Java. I’d been a junior contributor to Apache’s now defunct Avalon container for a couple of years before. Avalon introduced “Inversion of Control” (IoC). I hate the word framework in conjunction with DI. That’s because you could instantiate as many wholly separate containers as needed, register components (or other containers) into them, and by default, none of those contained things had reference to the container that contained it.

Dependency Injection is more of a thing for Java and C# than it is for Ruby or Python. Of course, Java runs in a Java virtual machine, which is a process on an OS, and we historically had container concepts with EAR and WAR file deployments, that were a massive mistake for Sun in the opinion of many. JavaScript has DI too, first introduced by Angular1.

Virtual Machines

Think VMWare, Amazon EC2 instances, or the equivalent Digital Ocean (etc) things. Each needs a wholly-separate operating system, and shares CPU, RAM and networking infrastructure with sibling VMs, but can’t casually discover the siblings, or reach into innards of the containing host operating system. The technology on the host that manages the guest VMs may expose file mounts, sockets servers, and graphical resources, but the directionality is clear. Each VM can host a number of processes as a normal machine installed OS would have.

Docker-Style Containers

Not to be confused with VMware style VMs, though they often go together. A host machine (physical or virtual) mounts a container with minimal (shared) operating system resources. It feels like a regular operating system, but conventions apply, and the contained is limited to a single application/service. Typically, that is a limit on the number of larger processes running. Say one ideally, though again, that is really only a convention. As before, the container knows about the contained, and the contained is limited in what it can connect to. Deployments focusing on this style of container always use fewer resources than deployments resting on VM solutions (above).


It is less obvious here but a visual rectangle of a UI that contains many smaller rectangles most likely guides the layout more than the contained guide the layout of the container. Maybe the container queries the contained about preferred size and all that. This is all about the ‘V’ in MVC (Model View Controller), and the M and C aspects are entirely different programmatic constructs. As you’d expect, all bets are off if there is absolute positioning going on.

There are strong component models like Java’s Swing framework (which Netscape donated to Sun in 1997 or thereabouts). The principles of containment are almost never fully realized, though, as the view assembly code can navigate casually to its own container and tinker with it, or sibling components/containers.

Even for Flash applications in web-apps (seemingly a rectangle in a rectangle), the principle of containment was weak. A technology called LiveConnect allowed the Flash doohickey to reach back out into the DOM of the container, although maybe the same origin applied. Flash is dead anyway, and nothing programmatic has assumed its place in the world of browser plugins.

The Web, Specifically

What a disaster. As with fat UIs the components in a browser tab can interfere with each other, regardless of the visual containment intentions. This is so bad today that you can’t have rectangles from modern web microframeworks (say Angular1, Angular2, EmberJS, and React) share space on the same page and have easy isolation. It just breaks, as the monkey-patching of bits of pieces of the DOM to get things working destabilizes things. Say Angular1 inadvertently disables EmberJS, or vice versa, or they each effectively kills the other. You have to revert to Iframes to guarantee isolation, and that is quite heavy with big aesthetic downsides.

I say it's a disaster because it is 2016 and we are 25+ years into the web — this should have been solved many years before. <div isolate>..</div> is what we needed, as well as a mechanism to declare inputs and outputs of the contained, and wide support for an HTML-import.

Circling back to dependency injection — this pattern/practice simplified the construction of non-visual parts of the UI. It is a trick, though, as the IoC can be subverted within the DOM. Components/services/directives can gain a reference to their implicit containers after a few lines of JavaScript.

Maybe in another decade, the DOM will become a better container/contained facilitator.

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.

container ,dependecy injection ,virtual machines ,docker ,user interface ,cloud

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}