design-patterns

Is unit of work a good pattern for transactions that will auto generate new objects (auto_increment id)?

拥有回忆 提交于 2020-01-14 00:33:50
问题 From the unit of work pattern i uderstand a method of doing typic transactions based on some domain repostiries (using a repository per domain object) . Example : after defining some repository objects in the UoW object , commit those repositories based on theyr state . Also the repositories should not contain any transaction logic . What happens when an insert() leads to a creation of a new object (auto generated id) that later on is needed by another object in the same transaction ? Unit of

using Composite Pattern to count the number of people in the world

好久不见. 提交于 2020-01-13 19:29:49
问题 I'm trying to make a Composite Pattern that counts the number of people in the world, the continent, the state... sorry no state but country my bad sorry Here is the pattern that I follow: I did this: but I am not sure it's right, because can I use leaf -> population ? Because when I did Composite Pattern for PC so its (PC= component from PC will be Cabinet = composite, from Cabinet will be HDD= leaf and Motherboard = composite, from Motherboard will be RAM = leaf and CPU = leaf). What I want

Symfony2 and be DRY approach in controllers

∥☆過路亽.° 提交于 2020-01-13 10:16:29
问题 I'm developing a small CMS for my company using Symfony2. I really love this framework. I love form classes and reusing them (that's all about forms after all). But (yes, there is a "but") I'm feeling like I'm doing the same stuff, copy and paste in all controllers . A code duplication that we hate. With all the business logic moved to Services and forms, events, persist actions in Doctrine, all my controllers do the same thing: Get the respository $this->get('mycompany.repository.entity')

“AsyncFuture<T>” or what? Future<T> obtained in a background thread — is it a pattern?

十年热恋 提交于 2020-01-13 08:43:14
问题 I'd like to have some work done in a background thread as simple as creating a Future var for it and then asking later for the calculated value. In pseudo-C#-code: AsyncFuture<int> asyncFuture = new AsyncFuture<int>(FuncToCalculateValue); //do some other work, or draw UI if(asyncFuture.NoErrorsHappened){ int realResult = asyncResult.Value; } I can implement such type by my own, but my question is: isn't that some kind of a known pattern? Is there maybe a name for it, or maybe even a framework

C# database wrapper design

只谈情不闲聊 提交于 2020-01-13 04:41:08
问题 I am designing a database wrapper for C#. Below are the two options I have: Option A: class DBWrapper:IDisposable { private SqlConnection sqlConn; public DBWrapper() { sqlConn = new SqlConnection("my connection string"); sqlConn.Open(); } public DataTable RunQuery(string Sql) { implementation...... } public Dispose() { if(sqlConn != null) sqlConn.Close(); } } Option B: class DBWrapper { public DBWrapper() { } public DataTable RunQuery(string Sql) { SqlConnection sqlConn = new SqlConnection(

Understanding the Single Responsibility Principle

微笑、不失礼 提交于 2020-01-12 18:47:10
问题 I am quite confused on how to determine if a single method has one responsibility being done just like the following code from the book Clean Code public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } } As the author stated on this code snippet: "... clearly does more

Understanding the Single Responsibility Principle

こ雲淡風輕ζ 提交于 2020-01-12 18:46:24
问题 I am quite confused on how to determine if a single method has one responsibility being done just like the following code from the book Clean Code public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } } As the author stated on this code snippet: "... clearly does more

Why does Scanner implement Iterator<String>?

做~自己de王妃 提交于 2020-01-12 14:18:41
问题 I was just wondering why java.util.Scanner implements java.util.Iterator? Scanner implements the remove method and throws an UnsupportedOperationException. But shouldn't a class, when implementing an interface, fulfill the contract of the interface? What is the use of implementing iterator and adding a method that throws an exception? Why not just avoid the implementation of the interface and keep it simple? One can argue that it is defined so that the class which might extend Scanner could

Why does Scanner implement Iterator<String>?

断了今生、忘了曾经 提交于 2020-01-12 14:16:25
问题 I was just wondering why java.util.Scanner implements java.util.Iterator? Scanner implements the remove method and throws an UnsupportedOperationException. But shouldn't a class, when implementing an interface, fulfill the contract of the interface? What is the use of implementing iterator and adding a method that throws an exception? Why not just avoid the implementation of the interface and keep it simple? One can argue that it is defined so that the class which might extend Scanner could

MVP on Asp.Net WebForms

末鹿安然 提交于 2020-01-12 09:56:20
问题 I'm not clear about this.... When having a gridview on the View, is the controller who has to set up the Data source, columns, etc? or I just have to expose the DataBinding stuff, fire it from the controller and let the html/codebehind on the view handle all the rendering and wiring up? To be more precise: on the view should I have private GridView _gv public _IList<Poco> Source { get {_gv.DataSource;} set {_gv.DataSource = value; _gv.DataBind();} } Or should it be (from MVP pattern - Passive