edy: Logging in class Diagram Uml Architectur

hello guys, I try to build a class diagram for our future Software, and I have the following Question. if I use the logging functions almost everywhere in our classes, why cannot define it as super class for all classes. that the logging function needed? and sorry for my bad English thank you in advance

  1. Hello edy,

    if you speak english better than german, then stick to english. This is a german forum, but we always try to help.

    Although - your question is likely to polarize, so I wonder if you are sincere or if you try to troll us.

    Whatever. Novice class modelers tend to move things that are used "everywhere" into a common "Object" superclass, but in most cases, this is wrong. A superclass describes a relationship "A is a B" - so a Cat Is A Mammal or an Employee Is A Person.

    Of course, everything you model Is A Object, but that's purely technical and doesn't create a valid inheritance relation. It's better to use a Logger-Object and pass it to the objects you create.

    You can also create a singleton "context" Object that provides access to a Logger-Interface. The important point is: make it replaceable. When you run unit tests, you don't want to write to your regular logging sink.

    In most cases, it's NOT right to create a static resource to provide the logger, because then you can't easily provide a dummy logger when you run unit tests

    Rolf

    --
    sumpsi - posui - obstruxi
    1. Tach!

      It's better to use a Logger-Object and pass it to the objects you create.

      Yes, usually a logger isn't a core part of business classes. It is more a dependency. If injected via Dependency Injection then there is no need to have a super class that contains infrastructural things besides the business case. This solves both problems: no need for a base class, and it can be replaced for unit tests.

      dedlfix.