design-principles

Does the Liskov Substitution Principle apply to subtype which inherited from abstract class?

喜你入骨 提交于 2019-12-13 12:55:41
问题 loosely speaking, Liskov Substitution Principle states that a derived class can be substitute in place of the base class without affecting the user. In the case when the base class is an abstract class, which means no user is using an instance of the base class, does the Liskov inheritance restrictions still apply to the derived class? 回答1: Just because you can't instantiate a particular class does not mean that you can't use it. In this scenario, the calling code is using the abstract base

wcf best design principles

烈酒焚心 提交于 2019-12-11 08:04:59
问题 I am looking to make some changes to an existing WCF service. I wanted to know if it would be best to make super methods such as a Save() that would use the values received to decide what action to take or if I should break the actions out into their own methods and expose those for the consumer to decide when to call them. For instance, I have a payment handler that receives notifications from our merchant when they make a payment attempt and its results. Would it be better for me to allow

How to manage interface segregation when using an IoC container? [duplicate]

夙愿已清 提交于 2019-12-11 03:59:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now. If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code? Assuming I have two interfaces

Should concrete implementation provide any public API not present in the interface it implements?

只愿长相守 提交于 2019-12-11 01:25:09
问题 " Code to interfaces " is considered good practice. Such code is easy to unit test and enables loose coupling. Users only know the interfaces and the onus of wiring concrete objects is upon the top-most level (this can be done in some init code or with the help of frameworks). My question is about following the practice of code to interfaces : does it imply that a concrete class can never declare any public method which is not present in its interface? Otherwise, it will force users to depend

Liskov substitution principle, preconditions and abstract methods

眉间皱痕 提交于 2019-12-10 18:05:24
问题 Liskov substitution principle (LSP) says: Preconditions cannot be strengthened in a subtype. In C#, I could violate the whole principle as follows: public class A { public virtual void DoStuff(string text) { Contract.Requires(!string.IsNullOrEmpty(text)); } } public class B : A { public override void DoStuff(string text) { Contract.Requires(!string.IsNullOrEmpty(text) && text.Length > 10); } } But, what would happen if A.DoStuff would be an abstract method: public class A { public abstract

Is using Java Reflection Bad Practice?

北慕城南 提交于 2019-12-10 17:59:53
问题 I am building an application for a client and I am in the situation where I need to have the ability to reference a field value via a string, i.e the users uses a string to define which field they want to change the value of, this is part of an abstract framework so technically I don't know the name of the fields they desire to change. Of course I could do this using hash maps, but I am considering using java reflection as this allows the fields to stay as fields of the object rather than the

Properly implement comparison of two objects with different type but semantically equivalent

一个人想着一个人 提交于 2019-12-10 02:06:31
问题 I've found a similar question How to compare two distinctly different objects with similar properties that may implicitly and/or in part reply to my question. Suppose I want compare (without a lot of nested conditions) this object: class ObjectA { public string PropertyX { get; set; } public char PropertyY { get; set; } public long PropertyZ { get; set; } } to a System.String . I'm interested only in equality or inequality (not a range of values about identity). Implementing IEquatable<string

UML help C# Design Principles

给你一囗甜甜゛ 提交于 2019-12-06 03:42:54
问题 Could anyone please point out the meaning of the graph below: What is the relationship between PolicyLayer and PolicyServiceInterface What is the relationship between PolicyServiceInterface and MachanismLayer. C# code would be also appreciated! Please note that the UML is from Agile Principles, Patterns, and Practices in C# By Martin C. Robert, Martin Micah 2006. Added on 15 2011/6/2 Do the following have the same meaning: 1) A solid line with a triangle at one end 2) A dashed line with a

Properly implement comparison of two objects with different type but semantically equivalent

北慕城南 提交于 2019-12-05 03:12:22
I've found a similar question How to compare two distinctly different objects with similar properties that may implicitly and/or in part reply to my question. Suppose I want compare (without a lot of nested conditions) this object: class ObjectA { public string PropertyX { get; set; } public char PropertyY { get; set; } public long PropertyZ { get; set; } } to a System.String . I'm interested only in equality or inequality (not a range of values about identity). Implementing IEquatable<string> in ObjectA is a proper choice? I don't care of what simply works , I want to identify the proper

UML help C# Design Principles

霸气de小男生 提交于 2019-12-04 08:11:34
Could anyone please point out the meaning of the graph below: What is the relationship between PolicyLayer and PolicyServiceInterface What is the relationship between PolicyServiceInterface and MachanismLayer. C# code would be also appreciated! Please note that the UML is from Agile Principles, Patterns, and Practices in C# By Martin C. Robert, Martin Micah 2006. Added on 15 2011/6/2 Do the following have the same meaning: 1) A solid line with a triangle at one end 2) A dashed line with a triangle at one end Added on 2011/6/3 1st What is the difference between: 1) A solid line with an arrow at