jeudi 13 décembre 2018

Pattern to Implement an OO interface to a C program written in an imperative style

Imagine a legacy C program written in an imperative style: top-down, no objects, and peppered with goto statements. This program implements a dependent in an observer pattern; i.e., the subscriber in a pub-sub architecture.

The task is to implement an OO interface to said program.

What design pattern fits best here? At first, I jumped to an Adapter pattern:

Adapter

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces [Go4, 8]

The problem here is that an adapter converts the interface of another class. in this case, there is no class to convert; C doesn't have classes.

Next I thought proxy:

Proxy

Provide a surrogate or placeholder for another object to control access to it. [Go4, 9]

This fits--sort of--but doesn't seem to capture the essence of what I'm trying to do.

Facade

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-elevel interface that makes the subsystem easier to use. [Go4, 9]

Perhaps... This may be the best option, but I'm not sure.

Which design pattern is most applicable in this scenario? Thx, Keith :^)

Aucun commentaire:

Enregistrer un commentaire