jeudi 17 septembre 2015

Design pattern for list of strings in class which represent a type or a message

The topic title is maybe not a good description for my question but i failed to find a better one.

Basicly a common problem i encountered over time was the definition of a class that contains constant variables which represent some kind of type or state.

<?php
class Notification {

     const TYPE_MAIL = 'mail';
     const TYPE_EXPORT = 'export';
     ...
}

You then store the object in a storage layer and later retrieve it again. Some common queries to retrieve these objects are 'where type = "mail"'.

Of course the application grows and types continue to be added. Could someone point me to a good design pattern to handle this kind of architecture problem? I would love to see some examples of constructions that avoid this kind of static declaration.

Thanks

Aucun commentaire:

Enregistrer un commentaire