lundi 20 mars 2017

Open/closed principle

I want to add the Write method to the TextLogger class. I am adding as follows. But Is this change not breaking the OPEN/CLOSED principle?

interface ILogger
{
    string Read();
}

class TextLogger : ILogger
{
    string Read()
    {
        //..
    }
}

class SqlLogger : ILogger
{
    string Read()
    {
        //..
    }
}

I add the write method like this.

interface ILogger
{
    string Read();
}

interface IWrite
{
    string Write();
}

class TextLogger : ILogger, IWrite
{
    string Read()
    {
        //..
    }

    void Write()
    {
        //..
    }   
}

class SqlLogger : ILogger
{
    string Read()
    {
        //..
    }
}

Aucun commentaire:

Enregistrer un commentaire