Skip to content

Blog

Stateless Rest Service Authentication

REST Services are considered stateless. Therfore a Rest Service must not hold any client state. If so REST Services can be scaled easily by adding new server nodes without to worry about session replication. But this also means that a REST-Client must send all authentication information with every request. There are several techniques to handle that and each of them has it’s pros and cons. This blog wants to discuss some different approaches. Why not just using stateful application services? The simplest way to implement authentication in an application service is to make it stateful. This means that the application service is aware of requests that the client made before some request. Therefore… Read More »Stateless Rest Service Authentication

A type-safe named query design approach for JPA

The starting point In a JEE you normally use the Java-Persistence-API JPA to access the data. JPA provides named queries which are statically defined queries with an unmodifiable query string. Because the query string is unmodifiable a client must still be able to provide parameters that concretize a query. Those query parameters are placed in the query string in a special format, e.g. :username. So if we define a named query in the simplest way it will look like this: @Entity @NamedQueries( { @NamedQuery( name = "findOrdersByUsername", query = "select distinct o from Order o JOIN order.user AS u where u.username = :username") } ) public class Order { ...… Read More »A type-safe named query design approach for JPA

The MVC pattern implemented with java swing

MVC Pattern Basics The MVC pattern describes a way to organize the components of a graphical user interface. Therefore it must cover all aspects of a user’s interaction with an application. If we take an analytic look at a graphical user interface we will understand why the MVC pattern is composed of the 3 elements model, view and controller. Model A model is an abstraction of something that you want to present the user in a view. Therefore there are two stereotypes of models: UI-model A ui model is an abstraction of a ui component’s state. Therefore it has properties like: focus, enablement, selection and so on. A good example… Read More »The MVC pattern implemented with java swing

Separation of api and implementation

In every project you have to deal with apis and their implementations. While a lot of projects separate the api from it’s implementation through different java packages (mostly named internal or impl), I want to show you another approach and tell you why this approach makes more sense. I call this other approach “implementation separation by packaging artifact”. Let’s take a look at a widly used project structure that separates the api from the implementation by using a separate impl package. This kind of separation is widely used but it has a some impacts on design and api usage as I will show now. Api and implementation dependencies differ The… Read More »Separation of api and implementation

Simplify service layer design using bean validation – jsr-303

Some weeks ago I wrote a blog about Pros and cons of service layer designs. While that blog addresses the service layer design with pure java, this blog is about a service layer design using java bean validation as defined by jsr-303. Both strategies that I have discussed in the Pros and cons of service layer designs blog can be implemented easier by using the java bean validation framework. Let’s take a look at the shared request and response type strategy. The problem of this strategy is that the request and response types are used in a lot of different service methods and therefore they must define the properties of all… Read More »Simplify service layer design using bean validation – jsr-303

Impact of proxy on equals and hashCode

A lot of frameworks create proxies  to apply aspect oriented programming or the lazy loading pattern. Hibernate for example uses cglib or javasissit to create lazy loading proxies. The famous springframework mainly uses java proxyies created via java.lang.reflect.Proxy.newProxyInstance(ClassLoader, Class<?>[], InvocationHandler) or cglib as well. Therefore it is important to know exactly how proxies work and the impact of proxies on your implementations. Especially when implementing basic methods like equals() and hashCode(). How proxies work A proxy is (like the name implies) not the real object. It is another object with the same interface as the real object. Since it has the same interface it can either delegate all calls to… Read More »Impact of proxy on equals and hashCode

Pros and cons of service layer designs

A service layer is a common approach in enterprise applications to encapsulage application specific use cases. So when I talk about service layers I mean the service layer pattern as described in the “pattern of enterprise application architecture” book by Martin Fowler. While the pattern describes the responsibility of a service layer from a high level architectural perspective, this blog is about to take a closer look at the most used service layer designs. Definition of a service A service provides methods for it’s clients. These methods are typically on a coarse-grained level and normally encapsulate use cases. Therefore the service layer methods are often the transaction boundary of an… Read More »Pros and cons of service layer designs

Handling complex object state with design

Some APIs that implement a complex object state management often violate the single responsibility principle and make the usage very difficult. When you do all aspects of the complex state management in one inferface the interface’s methods must be invoked in the chronological correct order. Such APIs are hard to understand and to integrate. What we really want are APIs that guide the client code programmers in such situations. Lets take a look at an API that breaks the single responsibility principle and let us think about the consequences for the client code programmer. If you take a look at the FTPClient API of apache commons you can see that all… Read More »Handling complex object state with design

Anemic vs. Rich Domain Models

There are a lot of discussions about rich and anemic domain models. Some developers tend to praise the anemic model, because of it’s simplicity while other blame the anemic model for it’s simplicity and they pray for the rich domain model. In this blog I want to show both models, the advantages and disadvantages that come with each model to give you a decision and discussion basis. The anemic model An anemic model is a domain model that doesn’t contain any logic. That is why the model is called anemic. It is just a container for data that can be changed and interpreted by clients. Therefore all logic is placed outside… Read More »Anemic vs. Rich Domain Models

GDPR Cookie Consent with Real Cookie Banner