vendredi 29 janvier 2016

Understanding bridge pattern and Java streams

I'm reading GoF design patterns and now I'm trying to undersand the Bridge pattern. Now, consider the Java streams (official documentation).

They introduced two kind of streams: Node streams and Filter streams. The last one uses Node streams to perform the actual wrtiting to/ reading from another stream. So Node streams incapsulate low-level io details. In the sense of GoF Bridge pattern, can Node Streams be considered as a bridge (Implementor) which are used by Filter streams?

If so, is it a good practice to not create a separate interface for a Bridge. E.g.

public interface DataWriter{

    public void write(Object);
}

In my case there might be two kind of implementatios: One that defines low-level io details, and one that performs convertions, validation and so forth ans uses underlying DataWriter to write data (to file system persistance store, Java OutputStream and so forth). Can I consider that the first one is a bridge and just write a JavaDoc for the interface in order to avoid creating another DataWriterImplementor interface?

Aucun commentaire:

Enregistrer un commentaire