New answers tagged

2

Preface For any given project, the answer to this question will likely differ. This is simply a result of structure and overall philosophy. It may be easy and straightforward in some instances, but extremely difficult and complicated in others. However, if this is a difficult problem, that is a very strong code smell: something is likely quite wrong with ...


0

Are there any more options I should consider? have a look at php constants instead of global variables consider using bit fields instead of a SYSTEM variable or constant


1

A Data Access Object should only really exist once in your application. The logic remains the same, the only things that are different are the values coming in and out of the methods the DAO provides. With that in mind, obviously the first thing that usually happens is implementing the DAO as a strong singleton, that is when you have a static method on a ...


1

Singleton is refering to the concept just only one instance and the way to get access to the instance (through the so famous static method getInstance()) But there's still an instance behind all of that. A built object with a sort of resticted access. In your case, I would rather go for DI approach (dependency injection). Like the first block of code you ...


7

I wouldn't use a singleton. It's a recognised anti-pattern, and makes testing difficult. I would much rather inject in a concrete implementation, and have your service reference a DAO interface (allowing you to inject different implementations in)



Top 50 recent answers are included