Click here to Skip to main content
13,447,300 members (39,061 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 24 Mar 2014

Vacuole Encapsulation

, 24 Mar 2014
Rate this:
Please Sign up or sign in to vote.
Encapsulation approach to bring data sources and implementations closer together, allowing reflection-like behavior in a format that mere mortals can read.

Before you Google “Vacuole Encapsulation,” let me introduce you to my totally-made-up programming idea called a Vacuole.

I was working on a problem where a single user had potentially 200 identical address objects (4 per US State). This overwhelming data load ultimately brought me to a solution where beans use maps for portable data storage, allowing the sharing of identical address values, condensing those 200 addresses down to as little as 4.

While I felt augmenting data storage with maps was a niche solution to a specific problem, it led me to some surprisingly comfortable synergies later on in validation and mapping. I developed a handful of simple utilities that were applicable to any value bean implementing Vacuole.

Vacuole Encapsulation

Vacuole Encapsulation is a slightly different approach from encapsulation. You still get standard issue encapsulation accessors and mutators. But, instead of variables, a Map is used for data storage with Vacuoles as the Object key. The most important aspect of this pattern, the Vacuole, contains everything and anything that the Bean and its contents need to be effective and thrive, such as:

  • Unique Identifier ( Random UUID? )
  • Classification ( Column name? useful for comparing like values)
  • Contract ( Validation Adaptors )
  • Data Type ( Eg: Class )
  • Field Length ( < input maxlength = ” ? ” … /> )
  • Required Input? ( * )
  • Or anything else you deem necessary

This behavior of using Maps with a Vacuole key can process data with very little code, making routine tasks like validation, mapping, and comparison, a refreshingly easy task with very shallow trace calls and zero reflection.

Case Example

You need to populate request data from a form. Where the Vacuole’s unique identifiers are applied to input name attributes of form elements, re-uniting each form variable input with the exact bean is easy. Here is an example of Validate/BeanMapping from a Request object:

public class VacuoleUtils {
    public static List<ValidationResult> handleRequest(HttpServletRequest req, 
                  List<VacuoleBean> vBeans) {
        List<ValidationResult> results = new ArrayList<>();
        for (VacuoleBean vBean : vBeans) {
            for (Vacuole v : vacuoleBean.getVacuoles()) {
                for (Validator val : v.getValidations()) {
                    Object value = req.getParameter(v.getId());
                    ValidationResult result = val.check(value);
                    if (result.pass()) vBean.setValue(v,req.getParameter(v.getId()));
                    else results.add(result);
        return results;

Vacuoles are still a curiosity for me, and I look forward to exploring and discovering the utility this little idea has in store.

At some point, with a blessing from Keyhole, I hope to make available some source code through Github! Until then, I recommend you take these concepts and apply them independently. Good luck!

– Ryan McCullough


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Keyhole Software
Keyhole Software
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

3 members

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180318.3 | Last Updated 25 Mar 2014
Article Copyright 2014 by Keyhole Software
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid