What's my Modularity
@bobpaulin
http://www2.pictures.zimbio.com/gi/Super+Rugby+Rd+12+Rebels+v+Reds+-eWcZZxaaJVl.jpg
“The bearing of a child takes nine
months, no matter how many
women are assigned”
- Fred Brooks
But could we make 9 babies in 9
Months….
http://www.smh.com.au/ffximage/2005/07/17/wrestling_wideweb__430x250.jpg
What is Modularity?
UNIX Rule of Modularity
Developers should build a program out of
simple parts connected by well defined
interfaces, so problems are local, and parts
of the program can be replaced in future
versions to support new features. This rule
aims to save time on debugging code that is
complex, long, and unreadable.
- Eric Raymond
What makes a module?
Java Application Architecture
Kirk Knoernschild
Testable
Deployable
Manageable
Natively Reusable
Composable
Stateless
Designing Modules
The modularizations include the
design decisions which must be
made before the work on
independent modules can begin.
- David Parnas
Changeability
Independent Development
Comprehensibility
A biological standard?
Evolvable
http://a66c7b.medialib.glogster.com/media/0c/0cdf43b19a5b5ae9f51f46208517c80434e08093c
52c679bb996022c27d9e0b8/cell-division-background.jpg
Transplantable
http://www.thinkgeek.com/product/e72e/
Containable
https://www.niaid.nih.gov/SiteCollectionImages/topics/im
munesystem/humanTCellSlide.jpg
Java Out of the Box
What's Missing in Java?
Versioning
1.0.0
Protection for Internal Classes
Security from unwanted classes
How Do We Deal?
Dependency Injection
Dependency Management
A good start but….
It doesn't actually stop us from doing
bad things
Project Jigsaw
➔ JEP 200: The Modular JDK
➔ JEP 201: Modular Source Code
➔ JEP 220: Modular Run-Time Images
➔ JSR 376: Java Platform Module System
Early Release Stuff working!
https://jdk9.java.net/jigsaw/
Inside a Module
module-info.java
module java.security.sasl {
requires java.logging;
exports javax.security.sasl;
exports com.sun.security.sasl.util to
jdk.security.jgss;
provides java.security.Provider with
com.sun.security.sasl.Provider;
}
No more JRE vs JDK Distinction
jlink
Build your own minimalist runtime!
Promised but not yet delivered
https://www.nlm.nih.gov/medlineplus/magazine/issues/fall10/articles/fall10pg5.html
OSGi
OSGi provides runtime modularity
Converting the Ball Of Mud to OSGi
Break Cyclical Dependencies
Consolidate cycle to one Jar
Consolidate cycle to separate Jar
Create BundleActivator classes
Register Services.
Import Services
Virtualization
Docker
Demo
Converting single JVM OSGi to
Containers
Add Docker File Generation to
Gradle
Add RemoteServiceAdmin
Build Docker Images and Start
When to use….
Parting thoughts for good modular
code….
No cyclical dependencies
Know how your modules need to
scale
Keep External Interfaces simple
Bob Paulin
Email
bob@bobpaulin.com Or
bob@apache.org
Twitter
@bobpaulin
GitHub
https://github.com/bobpaulin
CJUG
Meetup
http://www.meetup.com/ChicagoJUG/
Twitter
@cjug
Devoxx4Kids
Chicagoland
Website
http://devoxx4kids.org/usa/chicago/
http://www.meetup.com/Devoxx4Kids-
Chicagoland-Area/
Twitter
@devoxx4kids_chi
Off Heap
Java Pubhouse
Website
http://www.javaoffheap.com/
http://www.javapubhouse.com/
Twitter
@offheap
References
Parnas, D. L. On the criteria to be used in decomposing systems into modules.
Commun. ACM 15, 12 (December 1972), 1053-1058.
DOI=10.1145/361598.361623 http://doi.acm.org/10.1145/361598.361623
Knoernschild, Kirk. Java Application Architecture: Modularity Patterns with
Examples Using OSGi Addison-Wesley Professional 2012
Brooks, Fred. The Mythical Man-Month: Essays on Software Engineering
Addison-Wesley 1975
Raymond, Eric S. The Art of Unix Programming Addison-Wesley 2003
Perlis, Alan. Epigrams in Programming ACM SIGPLAN Notices 17 (September
1982) http://www.cs.yale.edu/homes/perlis-alan/quotes.html
Links
● Sonar http://www.sonarqube.org/
● Sonar Source Dashboard http://nemo.sonarqube.org/dashboard/index
● Docker https://www.docker.com/
● Apache Felix http://felix.apache.org/
● Amdatu Remote http://www.amdatu.org/components/remote.html
● Gradle https://gradle.org/
● Gradle Templates https://github.com/townsfolk/gradle-templates
● Apache Tika https://tika.apache.org/
● Tesseract OCR https://github.com/tesseract-ocr/tesseract
● Project Jigsaw http://openjdk.java.net/projects/jigsaw/

What's My Modularity

Editor's Notes

  • #2 So today's talk isn't really about anything new and sexy like Microservices or Data Science. However I've found many of the most interesting problems to work with are the ones that we've known about since the dawn of Computer Science and still grapple with today. For example how many people here have been on a project that has fallen behind schedule. Be honest. Ok how many times has the solution been to add more people? An how many of you are still not done? Well this quote should ring pretty true.
  • #3 1975 – Mythical Man Month I use it. Leads to the next question
  • #4 It Depends Can the project actually be broken down It depends on Modularity
  • #5 So let talk about what I mean by this.
  • #6 Here's one definition from the Unix Philosophy. I think this answers it pretty well for 2 sentences. But that doesn't really give me enough to work with. Lets go deeper. Lets talk about what makes a module.
  • #7 Anyone care to take a stab at this? Kirk Knoewschild Definition different Deployable Manageable Testable Natively Reusable Composable Stateless
  • #9 Simple – need to name Name = purpose Version – software evolves Together should be unique Developer should be able to identify and integrate
  • #10 Useless if it can only be used in one place It should also be easily removable from an application.
  • #11 Protect inner workiings from the public Sounds bad but helps with refactoring If exposed people will write code with it Once that happens Piss community off or dance around the problems Ever create a admin interface that a client found?
  • #12 David Parnas – Module design.
  • #13 We need to think about this Existing or new we have a tendency towards the ball of mud. (one big class. One big program) Here are some things he mentions we need to think about in his paper
  • #14 Hard – Fortune telling Where do we have questions. Where are we unclear Good candidate for change Encapsulate things that might change
  • #15 Loose coupling. The key to making 9 babies Separate deployable units Independent function - Manageable
  • #16 Cohesion Understood without the rest of the system Lets talk about Java… Java has a number of features that help with modularity ootb
  • #18 Packages - Groups of classes Imports – Allow classes from other groups into other classes
  • #19 Ways of protecting implementation details
  • #21 Currently packages can't be versioned Neither can jars
  • #22 By default classes are public No good way to restrict people from using them This is why Java never removes anything
  • #24 Interfaces and Spring Contexts
  • #25 We need to go beyond this. DI is only a start not a solution Still have public classes. No versioning.
  • #30 No more rt.jar or tools.jar
  • #42 Is a upcoming new technology based upon a number of older technologies A lot like virtualization but no hypervisor
  • #47 Native Libraries Similar Network ports Shared file systems But with this comes added complexity Discovery Orchestration What were code issues are now spread over the whole system