WhatsApp hack and other notorious data breaches
phones via the app’s voice-calling function. WhatsApp believed the spyware was developed by Israeli cyber surveillance
company NSO Group.
phones via the app’s voice-calling function. WhatsApp believed the spyware was developed by Israeli cyber surveillance
company NSO Group.


To conclude SOLID is a principle helps in Oops concepts. SOLID principle will help us to write loosely coupled code which is highly maintainable and less error prone.

SOLID are five basic principles which help to create good software architecture.
S stands for SRP (Single responsibility principle):- A class should take care of only one responsibility.
O stands for OCP (Open closed principle):- Extension should be preferred over modification.
L stands for LSP (Liskov substitution principle):- A parent class object should be able to refer child objects seamlessly during runtime polymorphism.
I stands for ISP (Interface segregation principle):- Client should not be forced to use a interface if it does not need it.
D stands for DIP (Dependency inversion principle) :- High level modules should not depend on low level modules but should depend on abstraction.
Why SOLID ?
SOLID principle will help us to write loosely coupled code which is highly maintainable and less error prone.

namespace SRP
{
public class Employee
{
public int Employee_Id { get; set; }
public string Employee_Name { get; set; }
///
/// Employee object
/// Successfully inserted or not
public bool InsertIntoEmployeeTable(Employee em)
{
// Insert into employee table.
return true;
}
///
///
public void GenerateReport(Employee em)
{
// Report generation with employee data using crystal report.
}
}
}
Employee’ class is taking 2 responsibilities, one is to take responsibility of employee database operation and another one is to generate employee report. Employee class should not take the report generation responsibility because suppose some days after your customer asked you to give a facility to generate the report in Excel or any other reporting format, then this class will need to be changed and that is not good.Employee’ class.public class ReportGeneration
{
///
///
public void GenerateReport(Employee em)
{
// Report reneration with employee data.
}
}

ReportGeneration’ class as an example of this principle. Can you guess what is the problem with the below class!!public class ReportGeneration
{
///
public string ReportType { get; set; }
///
///
public void GenerateReport(Employee em)
{
if (ReportType == “CRS”)
{
// Report generation with employee data in Crystal Report.
}
if (ReportType == “PDF”)
{
// Report generation with employee data in PDF.
}
}
}
If’ clauses are there and if we want to introduce another new report type like ‘Excel’, then you need to write another ‘if’. This class should be open for extension but closed for modification. But how to do that!!public class IReportGeneration
{
///
///
public virtual void GenerateReport(Employee em)
{
// From base
}
}
///
public class CrystalReportGeneraion : IReportGeneration
{
public override void GenerateReport(Employee em)
{
// Generate crystal report.
}
}
///
public class PDFReportGeneraion : IReportGeneration
{
public override void GenerateReport(Employee em)
{
// Generate PDF report.
}
}
IReportGeneration. So IReportGeneration is open for extension but closed for modification.
employee example to make it understandable this principle. Check the below picture. Employee is a parent class and Permanent and Contract employee are the child classes, inhering from employee class.
public abstract class Employee
{
public virtual string GetProjectDetails(int employeeId)
{
return “Base Project”;
}
public virtual string GetEmployeeDetails(int employeeId)
{
return “Base Employee”;
}
}
public class CasualEmployee : Employee
{
public override string GetProjectDetails(int employeeId)
{
return “Child Project”;
}
// May be for contractual employee we do not need to store the details into database.
public override string GetEmployeeDetails(int employeeId)
{
return “Child Employee”;
}
}
public class ContractualEmployee : Employee
{
public override string GetProjectDetails(int employeeId)
{
return “Child Project”;
}
// May be for contractual employee we do not need to store the details into database.
public override string GetEmployeeDetails(int employeeId)
{
throw new NotImplementedException();
}
}
List employeeList = new List();
employeeList.Add(new ContractualEmployee());
employeeList.Add(new CasualEmployee());
foreach (Employee e in employeeList)
{
e.GetEmployeeDetails(1245);
}
contractual employee, you will get not implemented exception and that is violating LSP. Then what is the solution? Break the whole thing in 2 different interfaces, 1. IProject 2. IEmployee and implement according to employee type.public interface IEmployee
{
string GetEmployeeDetails(int employeeId);
}
public interface IProject
{
string GetProjectDetails(int employeeId);
}
Now, contractual employee will implement IEmployee not IProject. This will maintain this principle.
public interface IEmployee
{
bool AddEmployeeDetails();
}
employee class will inherit this interface for saving data. This is fine right? Now suppose that company one day told to you that they want to read only data of permanent employees. What you will do, just add one method to this interface?public interface IEmployeeDatabase
{
bool AddEmployeeDetails();
bool ShowEmployeeDetails(int employeeId);
}
employee class to show their details from database. So, the solution is to give this responsibility to another interface.public interface IAddOperation
{
bool AddEmployeeDetails();
}
public interface IGetOperation
{
bool ShowEmployeeDetails(int employeeId);
}
employee will implement only IAddOperation and permanent employee will implement both the interface.public class Email
{
public void SendEmail()
{
// code to send mail
}
}
public class Notification
{
private Email _email;
public Notification()
{
_email = new Email();
}
public void PromotionalNotification()
{
_email.SendEmail();
}
}
Notification class totally depends on Email class, because it only sends one type of notification. If we want to introduce any other like SMS then? We need to change the notification system also. And this is called tightly coupled. What can we do to make it loosely coupled? Ok, check the following implementation.public interface IMessenger
{
void SendMessage();
}
public class Email : IMessenger
{
public void SendMessage()
{
// code to send email
}
}
public class SMS : IMessenger
{
public void SendMessage()
{
// code to send SMS
}
}
public class Notification
{
private IMessenger _iMessenger;
public Notification()
{
_ iMessenger = new Email();
}
public void DoNotify()
{
_ iMessenger.SendMessage();
}
}
Notification class depends on Email class. Now, we can use dependency injection so that we can make it loosely coupled. There are 3 types to DI, Constructor injection, Property injection and method injection.}
Reference : https://www.codeproject.com/Tips/1033646/SOLID-Principle-with-Csharp-Example
The Microsoft Web Protection Library (WPL) is a set of .NET assemblies that help you protect your web sites. The WPL includes AntiXSS that provides a myriad of encoding functions for user input, including HTML, HTML attributes, XML, CSS and JavaScript. WPL also includes the Security Runtime Engine that provides a wrapper around your existing web sites, ensuring that common attack vectors do not make it to your application.
The Microsoft Web Protection Library offers AntiXSS, an encoding library, to protect your current applications from cross-site scripting attacks and the Security Runtime Engine to help protect your legacy applications.
In .NET 4.0 a version of AntiXSS was included in the framework and could be enabled via configuration. In ASP.NET v5 a white list based encoder will be the only encoder.
As such the standalone versions of AntiXSS should be considered end of life.
The source and installers will remain online allow people using earlier versions of .NET to enable an alternative, whitelist based encoded but no further enhancements, outside of security fixes, will be made.
AntiXSS provides a myriad of encoding functions for user input, including HTML, HTML attributes, XML, CSS and JavaScript.
AntiXSS was merged into the .NET framework in v4.0. We recommend you use the bundled version, however we continue to make a standalone version available for older frameworks.
The Security Runtime Engine (SRE) provided a wrapper around your existing web sites, ensuring that common attack vectors to not make it to your application. Protection is provided as standard for
The SRE was meant as a defense in depth strategy, adding an bandage around your application until you could update the underlying code to provide encoding and SQL injection protection. It is no longer provided as a download and it’s use is not recommended, but source is available for those wanting to continue to use it or enhance it
2. Any app, Any platform
With .NET you can target any application type running on any platform. Developers can reuse skills and code across all of them in a familiar environment.