design-principles

Does Liskov Substitution Principle also apply to classes implementing an interface?

戏子无情 提交于 2020-02-03 11:00:22
问题 LSP states that classes should be substitutable for their base classes, meaning that derived and base classes should be semantically equivalent. But does LSP also apply to classes implementing an interface? In other words, if an interface method implemented by a class is semantically different from what user expects it to be, would this be considered as a violation of LSP? Thank you 回答1: No It only applies to subtypes. See the Wikipedia article for a brief summary. If you have a class B that

Concrete Types or Interfaces for return types?

眉间皱痕 提交于 2020-01-12 08:22:13
问题 Today I came to a fundamental paradox of the object programming style, concrete types or interfaces. Whats the better election for a method's return type: a concrete type or an interface? In most cases, I tend to use concrete types as the return type for methods. because I believe that an concrete type is more flexible for further use and exposes more functionality. The dark side of this: Coupling. The angelic one: A concrete type contains per-se the interface you would going to return

design pattern advice: graph -> computation

你说的曾经没有我的故事 提交于 2020-01-04 05:25:16
问题 I have a domain model, persisted in a database, which represents a graph. A graph consists of nodes (e.g. NodeTypeA, NodeTypeB) which are connected via branches. The two generic elements (nodes and branches will have properties). A graph will be sent to a computation engine. To perform computations the engine has to be initialised like so (simplified pseudo code): Engine Engine = new Engine() ; Object ID1 = Engine.AddNodeTypeA(TypeA.Property1, TypeA.Property2, …, TypeA.Propertyn); Object ID2

Strategy Pattern - multiple return types/values

巧了我就是萌 提交于 2019-12-24 05:21:52
问题 We are working on an image processing project using C# and EmguCV. Our team is composed of 3 people. To make faster progress, the 3 of us work on different sub-problems or experiment with different algorithms at the same time. Currently each of us creates a function that contains the major code we are working at and all of us make changes to the driver to add calls to our new functions. All this happens on the same file. We are using source control, so we have not stepped into each other toes

What's the difference between principles YAGNI and KISS?

不想你离开。 提交于 2019-12-23 08:36:02
问题 Obviously there are syntactical differences between YAGNI and KISS but I can't see any semantic differences between them. Are they really in essence just the same thing? 回答1: YAGNI (You aint gona need it) refers to over analyzing and implementing things that may or may not be needed. Sure algorithmic elegance is nice and all but most situation you dont need it. In general engineering terms you should be carefull not to include your own requirements so that you dont taint your customer needs

What's the difference between principles YAGNI and KISS?

旧巷老猫 提交于 2019-12-23 08:35:15
问题 Obviously there are syntactical differences between YAGNI and KISS but I can't see any semantic differences between them. Are they really in essence just the same thing? 回答1: YAGNI (You aint gona need it) refers to over analyzing and implementing things that may or may not be needed. Sure algorithmic elegance is nice and all but most situation you dont need it. In general engineering terms you should be carefull not to include your own requirements so that you dont taint your customer needs

Should I favour IEnumerable<T> or Arrays? [closed]

百般思念 提交于 2019-12-21 03:12:43
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . In many projects I work on, whenever I have to return a read only collection, I use the IEnumerable<T> interface and make it type specific like so: Public ReadOnly Property GetValues() As IEnumerable(Of Integer) Get 'code to return the values' End Get End Property Most of the

UML help C# Design Principles

a 夏天 提交于 2019-12-18 18:14:21
问题 I have a problem understanding an UML below: Specifically, what is the relationship between PersistentSet and ThirdPartyPersistentSet ? What is the relationship between PersistentObject and ThirdPartyPersistentSet ? Please note that the UML is from Agile Principles, Patterns, and Practices in C# By Martin C. Robert, Martin Micah 2006. Chapter 10 Thanks in advance! 回答1: The relationship between PersistentSet and ThirdPartyPersistentSet is an Aggregation, which means the PersistentSet contains

What is the meaning and reasoning behind the Open/Closed Principle?

独自空忆成欢 提交于 2019-12-17 10:25:11
问题 The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design? 回答1: Specifically, it is about a "Holy Grail" of design in OOP of making an entity extensible enough (through its individual design or through its participation in the architecture) to support future unforseen changes without rewriting its code (and sometimes even

REST API question on how to handle collections as effective as possible while still conforming to the REST principles

依然范特西╮ 提交于 2019-12-14 03:41:55
问题 Im pretty new to REST but as far as i have gathered i understand that the following URL's conform to the REST principles. Where the resources are laid out as follows: /user/<username>/library/book/<id>/tags ^ ^ ^ ^ |---------|-----------|---|- user resource with username as a variable |-----------|---|- many to one collection (books) |---|- book id |- many to one collection (tags) GET /user/dave/library/book //retrieves a list of books id's GET /user/dave/library/book/1 //retrieves info on