DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Harnessing the Power of Integration Testing
  • Auditing Tools for Kubernetes
  • Execution Type Models in Node.js
  • Clear Details on Java Collection ‘Clear()’ API
  1. DZone
  2. Coding
  3. Java
  4. Review Structural Changes in Java Code

Review Structural Changes in Java Code

Check out this post to learn more about code reviews and Java code structure!

Wojciech Gdela user avatar by
Wojciech Gdela
·
Nov. 15, 19 · Presentation
Like (7)
Save
Tweet
Share
42.34K Views

Join the DZone community and get the full member experience.

Join For Free

Java code review

Read on to learn more about code reviews and Java code structure!

Code reviews are a proven practice to help keep your code as clean as possible. Doing it means nitpicking every detail of each method and class: naming, length, responsibility, algorithm, style, and so on. You have to look at everything used to ensure that lines of code are understood not only by the machine (compiler) but also by humans. As humans, you or your fellow programmers will have to maintain the code.

What about the bigger picture? Well, there’s the architecture of the system. Perhaps, it just sits with the leads of your team, or perhaps it is properly documented, but generally, people know which applications or microservices are integrated with each other and in what direction the data flows between them. Somebody cares about this highest level of modularity.

You may also like: Java Code Review Checklist

But I think there’s a gray area between those two: the method and class level changes, and the whole system architecture changes, namely the inner composition of a single application or microservice. Or to be more precise, the composition of a lump of code that is built together as a unit. For a lack of a better word, let’s call it a module.

Looking After the Composition of Modules

Granted, nowadays, everybody uses microservices. If each module is really small, and if it contains only a couple dozen classes or so, the composition of the module doesn’t matter. Maybe, you don’t even bother grouping the module’s classes into separate packages.

But if you do, for example, if you do monolith-first development, or if your microservice is not so micro, then you should care how the code inside your module is structured. In the first case, you do this so that you have clearly defined components constituting your monolith that can be later promoted to microservices, without risking that your code will become a big ball of tangled classes. In the second case, you do this just to be able to work on one component at a time, without having to understand the entire big module.

To assure this, you need to keep an eye of how the classes are grouped, and how those groups of classes — components — depend on each other:

Sample visualisation of dependencies between components of a module.

Sample visualization of dependencies between components of a module

So, do you analyze package declarations and import statements while you are reviewing code changes? I bet you don’t!

When writing code, you just type the class name, and the IDE kindly adds the import statement for you. You don’t notice that you’ve just added a new dependency between components. When reviewing code, out of habit, you typically skip this seemingly boilerplate information without a second thought.

Tools to the Rescue

That’s why I’ve written Socomo. This is a tool that screams at you when a new component has been added, or more importantly, a new dependency has been introduced. It does so by keeping a socomo.html file with such information in your project, which changes along with the code. This way, in a single commit, besides actual code changes, you’ll see the higher-level view of structural changes, like so:

Diff that includes Socomo supplied information about newly introduced dependencies.
Diff that includes Socomo-supplied information about newly introduced dependencies
A similar principle about functionality is also provided by this commercial product Softagram. It integrates with your version control system, and to each pull request, it adds a report with a summary of the impact of the changes:
Pull request comment added by Softagram about introduced structural changes

You can even go a step further — proactively guard composition changes by declaring the rules of the composition and using tools like ArchUnit to enforce them:

Compositon rules declared as unit test with the help of ArchUnit.

Composition rules declared as a unit test with the help of ArchUnit

Though sometimes it can be hard to know upfront how the code should be structured, the composition of an application or service is a kind of emergent design. So please, keep an eye on it while you're adding more code so that the design emerges in the correct direction.

I hope you enjoyed!

Further Reading

Java Code Review Checklist

Code Review Essentials

code style Java (programming language)

Published at DZone with permission of Wojciech Gdela. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Harnessing the Power of Integration Testing
  • Auditing Tools for Kubernetes
  • Execution Type Models in Node.js
  • Clear Details on Java Collection ‘Clear()’ API

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: