In postul precedent am descutat despre o problema care poate sa apara cand expunem intr-un API metode virtuale, care sunt apoi suprascrise de catre un alt dezvoltator. Iar o versiune ulterioara a API schimba comportamentul aplicatiei in asa fel incat suntem obligati sa schimbam codul care foloseste API expus. Mai jos gasiti o posibila solutie la aceasta problema. public abstract class FooBase { private void DoAction() { // Custom code that can be executed by our method. DoActionCore(); // More custom code that can be executed by our method. } public virtual void DoActionCore() { // Some action } } public class MyCustomFoo : FooBase { public override void DoActionCore() { // My custom code of MyCustomFoo that will be // executed by DoAction method from base class. } } O solutie de acest gen o sa functioneze, doar daca cel c...
DREAMER, CRAFTER, TECHNOLOGY ENTHUSIAST, SPEAKER, TRAINER, AZURE MVP, SOLVING HARD BUSINESS PROBLEMS WITH CUTTING-EDGE TECHNOLOGY