C # interface segregation principle example of confusion

I'm new to programming, and it's hard for me to figure out how to effectively apply the principle shown in the following link (ATM):

http://www.objectmentor.com/resources/articles/isp.pdf

It basically starts with a design that does not complain about ISPs (the principle of segment separation) and moves forward to reorganize behavior on different interfaces.

My question is: Do we not use interfaces to express general behavior among inappropriate (or not) related abstractions?

What is the point of encapsulating methods in an interface if even one is not used in conjunction with classes that are going to implement them? In which scenario can this be considered useful?

If we continue the line of the example, the following code will be indicated:

    public interface Transaction 
    { 
        void Execute(); 
    }

    public interface DepositUI 
    {
        void RequestDepositAmount(); 
    }

    public class DepositTransaction : Transaction 
    { 
     private DepositUI depositUI; 
     public DepositTransaction(DepositUI ui) 
    { 
        depositUI = ui; 
    }   
     public virtual void Execute() 
    { /*code*/ 
      depositUI.RequestDepositAmount(); 
      /*code*/ } 
    }

    public interface WithdrawalUI 
    { 
      void RequestWithdrawalAmount(); 
    }
    public class WithdrawalTransaction : Transaction 
    { 
        private WithdrawalUI withdrawalUI;
        public WithdrawalTransaction(WithdrawalUI ui) 
        {
            withdrawalUI = ui; 
        } 
        public virtual void Execute() 
        { /*code*/ 
            withdrawalUI.RequestWithdrawalAmount(); /*code*/ 
        } 
    }
    public interface TransferUI 
    { 
        void RequestTransferAmount(); 
    }
    public class TransferTransaction : Transaction 
    { 
        private TransferUI transferUI; 
        public TransferTransaction(TransferUI ui) 
        { 
            transferUI = ui; 
        } 
        public virtual void Execute() 
        { /*code*/ 
            transferUI.RequestTransferAmount(); 
            /*code*/ 
    } 
    public interface UI : DepositUI, WithdrawalUI, TransferUI { }

, , - :

UI impui = new IMPLEMENTATIONUI(); // Some UI implementation
DepositTransaction dt = new DepositTransaction(Gui);
dt.Execute();

, , IMPLEMENTATIONUI ? , SRP?

+3
1

( ) ?

, SOLID . Transaction - . DepositTransaction WithdrawlTransaction. ISP ( ) , , Transaction . , SOLID:

void ExecuteTransaction(Transaction transaction)
{
    transaction.Execute();
}

, , . .

, WithdrawlTransaction DepositTransaction; ExecuteTransaction , .

ExecuteTransation(withdrawl_TransactionObject);

ExecuteTransaction(deposit_TransactionObject);

:

ExecuteTransaction(unanticipatedNewTypeOf_TransactionObject);

, , IMPLEMENTATIONUI ? , SRP?

, , . , / , IMPLEMENTATIONUI.

, , , , . " " , , .

+1

All Articles