A way to implement partial classes in java

Before going that route, you might want to consider the Builder design pattern. That allows your service to aggregate implementations that are implemented in separate classes. No need for a pre-compiler, and very clean from an OO perspective.

Each component class has a specific, narrow responsibility, with the service class enlisting the services of it's component classes to implement just the responsibility of the service.

If you really want to (not recommended), you can use a pre-processor to assemble parts of a class prior to compilation.

The only scenario where a pre-processor might make sense is if some of your implementation is code-generated and other parts are hand-coded. A straightforward approach might be to #include the externally defined class fragments in your main .java file and run a C pre-processor over the file before compilation.


There is nothing like partial classes in Java. You can achieve many of the same benefits using aggregation, delegation, and abstract base classes.

(I have caved to peer pressure and eliminated the “thankfully” remark that has generated so much heat in the comments. Evidently that little aside seems to have earned me four downvotes, despite being irrelevant to the answer.)


Aspectj can be the answer to C#/.net partial class feature! Spring Roo is one of the typical development framework using aspectj to divide a class functionalities into several different files.