Design Flashcards
In computer programming, a … is a reference that does not protect the referenced object from collection by a garbage collector, unlike a strong reference
weak reference.
Suppose a tree view in a Windows Forms application displays a complex hierarchical choice of options to the user. If the underlying data is large, keeping the tree in memory is inefficient when the user is involved with something else in the application. We are able to reconstruct the tree once it gets in focus. How would you reference the tree data to allow for optimal memory use.
By a weak reference. That would allow garbage collector to eventually reclaim the memory if needed and we would reconstruct it once it comes to be presented, and other parts might be reclaimed if not used to make memory for this one.
To prevent need for explicit unregistering of the event handlers, you would you which type of reference to the handler. (prevents memory leaks)
Weak reference.
Which data structures are mostly using weak references?
Symbol tables like weak map. Cache data structures.
What letters in the acronym SOLID stand for
Single responsibility Open/Closed Liskov substitution Interface segregation Dependency inversion
Which property of the software elements the “Open/Closed principle” refers to
Every class or other entity should be open for extension but closed for modification. This means that adding new parts of the concept like subtype or concrete implementation should not require change of the source but usage of the language tools to extend the meaning or semantics.
What does “interface segregation” refer to?
Better to have more independent interfaces than only big one. Better said, client should know only about the interface it needs to do its work and not more.