Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

When I am adding dependencies in Scala, I tend to use mixin trait components for those that are inherit to the class itself. For example, DaoGenerator extends Generator

However, for trait components likes FileIO, it is less straight-forward. If the DaoGenerator class requires it, I tend to make a judgement call. I feel like it can be either a trait component, object, or package object.

If it is part of the classes "responsibility", I add it as trait component. A generator class will most likely need to access file objects in the project so I add it as a trait component.

But if it was any other class, I tend to like to add it as either an object or package object, simply because it is cross-cutting concern. But when do you choose an object over a package object? For logging and configuration, I use package object only because it feels right.

What's your rule of thumb for these cases?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.