Adam Bien's Weblog

Friday Oct 18, 2013

Bureaucratic Design With Java EE

You can structure your Java EE applications without any further thinking by placing the contents into Java packages with names like: "exceptions", "beans", "interfaces" or whatever else emphasizes the obvious content, but not the actual responsibility. The question to answer is: how often do you actually searching for exceptions or interfaces?

In the following screencast, I used the ancient ECB pattern to structure Java EE applications:

My following pet projects: https://github.com/AdamBien/lightfish, https://github.com/AdamBien/e2ftp, http://x-ray.adam-bien.com, as well as, several commercial projects were already built according to the structure described in the screencast with good experiences so far.

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

[See also an in-depth discussion in the "Real World Java EE Patterns--Rethinking Best Practices" book (Second Iteration, "Green Book"), page 419 in, chapter "Entity Control Boundary (ECB)—The Lean Way"]

See you at Java EE Workshops at MUC Airport, particularly at the Java EE User Architectures workshop!


NEW workshop: Microservices with Java EE 7 and Java 8, January 26th, 2015, Airport Munich

A book about rethinking Java EE Patterns

Comments:

Not sure I follow you entirely here. You state you don't want to name things after technical terms but just have made up new ones in the package names "boundary", "control" and "entity" and structure your project along these lines. So you traded one kind of technical separation for the other kind.

What's wrong with staying with "blog" as the high level package name and just putting all three classes into the very same package. This has the benefit, that you can even make components, that other parts of the system shouldn't even use (as they make up the internals of you Blog component) package private. This might result in a few more classes inside the package but the view from the outside is much more focussed as the compiler helps you detecting what you're allowed to use and what not.

Read more on that approach at http://www.olivergierke.de/2013/01/whoops-where-did-my-architecture-go/

Cheers,
Ollie

Posted by Oliver Gierke on October 18, 2013 at 03:25 PM CEST #

@Oliver,

I always structured components with sub-packages and had good experiences so far:
- developers liked the clear structure. I got only good feedback so far.
- with sub-packages it is very easy to measure the dependencies between components and automatically validate the architecture with simple tools.
- you can leverage package-private visibility for additional encapsulation / easier communication within the package.
- you can build components without the boundary and so components not accessible to the presentation layer.

However, I made bad experiences with my own naming. I switched to ECB and since then I never had to justify that in boring meetings :-).

Btw. "my" components never comprise 3 classes. A typical component consist of 10 - 20 classes.

thanks for your comment!,

--adam

Posted by Adam Bien on October 18, 2013 at 10:36 PM CEST #

awesome java

Posted by 117.242.144.46 on October 19, 2013 at 08:13 AM CEST #

okay okay questions

Posted by 117.242.144.46 on October 19, 2013 at 08:14 AM CEST #

hi Adam,

Why is it the responsibility of the boundary to persist the entity ? I would imagine one would defer that to the control layer

/rune

Posted by Rune Molin on October 19, 2013 at 02:00 PM CEST #

Haven't watched your screencast, but I want to share an idea:

Why do companies continue to use their company's web domain as a prefix for all packages?

Most, if not all Java EE applications have no security policy applied to Java packages, so why bothering using "com.mycompany.mydepartment.myteam.myproject" before everything?

Just use "package projectname;" as root, and then the rest.

Posted by Bruno Borges on October 28, 2013 at 08:44 AM CET #

@Bruno,

a very good point. For me the company name was always a set default. I never thought about that.

I will steal your comment for the next post :-)

thanks for the inspiration!,

adam

Posted by Adam Bien on October 28, 2013 at 07:12 PM CET #

Hello Adam.

In what package you will put classes with @Named annotation (for example Posts list).

Your BlogEngine is looks like a first step to Rest (savePost, getPostById, getAllPosts) because of @Sateless annotation and injected EntityManager or some kind of Repository.

Does it's not good to mix @Named and @Stateless in one bean?

And you don't have '.core.' package so it's not enterprise :)

Thank you.

Posted by Sergey on October 31, 2013 at 05:23 PM CET #

Hi,

You state you're never design your application by technical structures. Where would you pack exceptions to? Especially if they are used through the whole project.
Moreover do you allow calls from a.boundary to b.boundary/b.controller and a.controller to b.controller where a and b are different domain packages.
Thank you

Posted by Manfred Pauli on November 07, 2013 at 12:22 AM CET #

@Bruno,

the use of the company domain was recommended by Sun as a way to preserve package namespace uniqueness and as a way of "badging" the code.
It is still a good idea to name packages this way, even if they are not destined for public consumption.

Posted by Andy on January 22, 2014 at 02:52 PM CET #

Hi,

Iam actually a PHP developer trying step by step to learn Java EE,

from the following tutorial i've tried to implement the ECB pattern tell me if iam wrong

http://www.adam-bien.com/roller/abien/entry/bureaucratic_design_with_java_ee

- Entity -> JPA entity
- Control -> Managed Bean
- Boundary -> Session bean

Actually i maded a component that retrieve page content from a table "pages" following to the id (Page id) provided by the Managed Bean.

i want to know how to do after ?? i mean should i create a servlet and Inject the Boundary in it and work with a simple JSP pages ??

or work with JSF and use the managed Bean inside the component just created ( Control ) ?? what the correct way to do the job ?

ps: my goal is to implement a CMS like joomla just for example to learn java EE.

thanks.

Posted by Ryadh on April 14, 2014 at 02:30 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License