mercredi 15 novembre 2017

Design pattern for self-referencing ordered objects (C#/EFCore)

First I apologise if I should have been able to find this myself through search... I'm rusty and learning a lot of new stuff so I'm not even sure if I'm using the right terms to describe what I want - don't kick the noob please :)

Question: Part 1 - Specific scenario I am trying to build classes to produce a tree of "goal objects", where

a) order matters and needs to be retained,

b) each goal object in the tree may stand alone as a single object, or comprise a collection of subgoals (and those subgoals further subgoals etc - let's say to a depth of 5 levels),

c) ability to edit the tree efficiently is necessary (including changing the order or index of any goal object, adding / removing / reordering / moving subgoals, pruning/adding branches to the tree). I can certainly work out a way to do this, but I strongly suspect my way will be highly inefficient both in terms of memory / processing and in terms of quantity of code required to manage the editing etc.

My question therefor: Can anyone point me to a design pattern or tutorial that will show me an efficient way to do this - or something similar that I can adapt? (I am currently working in C# & ASP.NET Core with EFCore pointing to SQLserver)

Part 2: Recommendations for a book / site that has an excellent set of fundamental design patterns suitable for C# would also be welcome.

Many thanks for any help you can offer. Chris

Aucun commentaire:

Enregistrer un commentaire