Is this the Open/Closed principle? And if not
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can create new repositories for different data structures by extending RepositoryBase in different ways, without having to modify the code in RepositoryBase. That is the core meaning of the open/closed principle. That said, the open/closed principle is a general design principle and not a design pattern. The main design pattern visible in the relation of the Save and IsValid methods is Template Method.
|
Open closed principle
Tag : chash , By : ArdentRogue
Date : March 29 2020, 07:55 AM
This might help you I understand that this principle states that a module is open for extension but closed for modification, and this is clear when we want to upgrade/modify a method in some class - we create another class that inherits the base class and then override the base method here in order to keep both functionalities. , TL;DR
|
SOLID - are the Single Responsibility Principle and the Open/Closed Principle mutually exclusive?
Date : March 29 2020, 07:55 AM
I wish did fix the issue. This feels like a discussion of the semantics of 'extend a classes behaviour'. Adding the new type to the factory is modifying existing behaviour, it's not extending behaviour, because we haven't changed the one thing the factory does. We may need to extend the factory but we have not extended it's behaviour. Extending behaviour means introducing new behaviour and would be more along the lines of an event each time an instance of a type is created or authorising the caller of the factory - both these examples extend (introduce new) behaviour. public interface IProductFactory
{
Product GetProduct(string type);
}
public class ProductFactory : IProductFactory
{
public Product GetProduct(string type)
{
\\ find and return the type
}
}
public class ProductFactoryAuth : IProductFactory
{
IProductFactory decorated;
public ProductFactoryAuth(IProductFactory decorated)
{
this.decorated = decorated;
}
public Product GetProduct(string type)
{
\\ authenticate the caller
return this.decorated.GetProduct(type);
}
}
|
OO Design Principle - Open Closed Principle
Date : March 29 2020, 07:55 AM
|
What is difference between the Open/Closed Principle and the Dependency Inversion Principle?
Tag : oop , By : Star Gryphon
Date : March 29 2020, 07:55 AM
|