Are circular class dependencies bad from a coding style point of view? [closed]

In general, I would call circular dependencies a Code Smell. Note that the term ‘Code Smell’ mainly indicates that ‘here is a piece of code that requires special attention, and is likely to benefit from redesign.’

In most cases I would strongly consider a design where a circular dependency is not necessary, but in rare cases it may be okay.

In your example, the ConnFactory seems redundant, but that may be because your example has been trimmed down. It seems to me, however, that the Connection creation logic would be better if it was moved to the DBInfo class. When you already have a class that contains data about a database, it seems only natural to make it responsible for creating a connection to that database.

Leave a Comment