D
D
Django Almighty2020-04-23 19:10:24
OOP
Django Almighty, 2020-04-23 19:10:24

The principle of openness-closedness on an example?

More details, please explain.
There is the principle of OCP - the Open Closed Principle (Openness-Closeness).

Please explain with an example.

Change has an abstract class BaseData

public abstract class BaseData
    {
        public virtual void Get()
        {

        }
    }


There is a class AdminData which is inherited from BaseData
class AdministratorData : BaseData
    {
        public override void Get()
        {
            base.Get();
        }
    }


Now a question. How can I check the conditions for displaying data for an administrator, or for a normal user, without using if, switch (the use of these select statements violates the OCP principle)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-04-23
@DanielMcRon

Notation with example https://metanit.com/sharp/patterns/5.2.php
Pattern example
https://metanit.com/sharp/patterns/4.3.php
Open for extension, closed for modification.
I think after these links questions should disappear
And it is not always possible to perfectly fulfill all the principles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question