Search code examples
c#oopumldesign-principles

UML help C# Design Principles


I have a problem understanding an UML below:

UML Image

Specifically, what is the relationship between PersistentSet and ThirdPartyPersistentSet? What is the relationship between PersistentObject and ThirdPartyPersistentSet?

Please note that the UML is from Agile Principles, Patterns, and Practices in C# By Martin C. Robert, Martin Micah 2006. Chapter 10

Thanks in advance!


Solution

  • The relationship between PersistentSet and ThirdPartyPersistentSet is an Aggregation, which means the PersistentSet contains one or more ThridPartyPersistenSet instances. This is a "weak" relationship, meaning the instances of ThirdPartyPersistentSet can exist outside of the PersistentSet.

    The relationship between PersistentObject and ThirdPartyPersistentSet is a Dependency, meaning basically ThirdPartyPersistentSet needs a PersistentObject to do it's work.

    So, to translate this to code, your PersistentSet would contain something like this:

    public class PersistentSet
    {
        public List<ThirdPartyPersistentSet> Items { get; }
        ...
    }
    

    And your ThirdPartyPersistentSet would look something like this:

    public class ThirdPartyPersistentSet
    {
        private PersistentObject _object;
        public ThirdPartyPersistentSet(PersistentObject obj)
        {
            _object = obj;
        }
        ...
    }