|
No, I meant my answer is incomplete one. I just gathered possible things to answer your question.
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|
|
Oh, I am sorry. I understood it differently. Thank you for your articles, I am reading them at the moment. They seem to have alot on ASP.NET side of the website, very informative.
Regards
|
|
|
|
|
Over the years I seem to go back and forth over what I prefer regarding multiple method names vs a single method with a discrimination parameter.
Sometimes I prefer multiple, similar methods:
LogError(sometext)
LogWarning(sometext)
And other times I see it more as a single method with an enumerated parameter:
Log(type, sometext)
It seems pretty subjective as to what conveys intent best and makes using the class easier.
Any opinions? (Particularly interested in thoughts that contain an objective reason. I already have subjective thoughts that keep varying over time. )
Thanks.
|
|
|
|
|
Harley L. Pebley wrote: Any opinions?
There are bigger problems to worry about would be my thought.
|
|
|
|
|
Other problems, of course. Relative size is a matter of opinion. In this case, the API is the primary way for users to access the rest of the product. It's pretty important.
|
|
|
|
|
Harley L. Pebley wrote: It's pretty important.
No it isn't. Which is obvious based on your experience. Both exist and both are used. Unless you can demonstrate that a significant number of bugs result from one or the other then neither is 'better'.
And it is possible that one or the other is better based on specific usage (class and how it will be used.)
And lets say you can determine that bugs are caused by this, how do those number of bugs compare to the ones caused by logic, design and requirement problems compare?
|
|
|
|
|
jschell wrote: No it isn't. Which is obvious based on your experience. LOL. Pretty condescending statement, don't you think?
jschell wrote: Unless you can demonstrate that a significant number of bugs result from one or the other then neither is 'better'. Sure, that's one way to measure 'better.' And there are two sides to that bug count: the users' and the implementers'. But there are other measurements of 'better' too: ease of discover-ability, semantic clarity, ease of use and ease of implementation among them. It's these more subjective qualities that I was looking for feedback and opinion on.
jschell wrote: And lets say you can determine that bugs are caused by this, how do those number of bugs compare to the ones caused by logic, design and requirement problems compare? Sorry, I don't understand the relevance of this question. Are you still trying to make the point that this isn't important? If so, that's fine. I simply disagree. The floorplan and architecture of a house is just as important as the quality of materials and workmanship in framing, plumbing and electrical work. If any of it sucks, home buyers will look elsewhere. The API of a public library is as important as the private implementation. If either one sucks, users will look for alternatives.
|
|
|
|
|
Harley L. Pebley wrote: LOL. Pretty condescending statement, don't you think?
Not sure I understand that. Perhaps you misunderstood what I was saying.
You already pointed out that you have seen both used AND that it is unclear to you that either is better. Those two things together represent your "experience" and it is that to which I was referring.
Harley L. Pebley wrote: But there are other measurements
I doubt it. Especially the "ease of implementation". But if you know of a way to measure (some objective process that arrives at a numerical result) then I would certainly like to hear about.
Of course someone might just like it better, but that isn't the same.
Harley L. Pebley wrote: Sorry, I don't understand the relevance of this question.
The answer to the original question is not relevant unless you can show that the number of problems caused by this are significant. That can only occur if either your application has a very low number of bugs caused by the things I mentioned (which is where I see most bugs occur) or because, in fact, this idiom causes a massive number of bugs in your application (overriding the other type.)
If that isn't your situation then focusing on reducing the other types of bugs is more effective.
|
|
|
|
|
jschell wrote: Perhaps you misunderstood what I was saying. Perhaps so. Typically when I hear people refer to "in my (your) experience" they are referring broadly to the sum total of all experiences, not narrowly to the one under discussion. I apologize.
As to the rest of our conversation, we're going meta into the importance/relevance of the question relative to other things and away from my original question. I think we view things through different lenses and just disagree, which is cool. Different perspectives provide food for thought.
Thanks for the feedback.
|
|
|
|
|
According to Robert C. Martin's Clean Code, use different functions: the function names give you additional information on the purpose, thus making the code better readable.
|
|
|
|
|
According to Eddy, it is not DRY.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Interesting. How do you see multiple methods violating DRY?
|
|
|
|
|
Harley L. Pebley wrote: How do you see multiple methods violating DRY? Multiple methods do not violate the principle. Repeating a specific value in a methodname, while you have declared an enum that holds the same information would; aight, granted, DRY does not directly apply to method-names.
It is as effective as copying sprocs to a slightly different name and changing a single integer that's updated. Even if you do not copy the sproc-body, you'd still end up with more securables and more failure-points.
The compiler will also not warn about missing methods when someone extends the enum. The biggest difference is that it makes it impossible to use the method in a loop, passing all the enum-values (and that might be a good thing)
From another perspective;
A boolean can be viewed as an enum with two values. I can see the value of methodnames like "Hide" and "Show", even with the existence of the Visible-property. That's propably because their semantics add value; it wouldn't if those methods were called "VisibleTrue" and "VisibleFalse" - that's just a crappy way of saying "Visible = false".
..then again, I upvoted jschell; the compiler will accept both, and there is no "one true way" of doing things. Anything that helps one to maintain the code is welcome.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Repeating a specific value in a method name, while you have declared an enum that holds the same information would;
Ah, right. I agree, it would be pretty confusing to have the name and an enum both. Sorry, I guess in my original post I didn't make it clear that I intended those to be mutually exclusive options.
Thanks.
|
|
|
|
|
Well, the title kinda does that
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the pointer to Clean Code. I obviously need to go reread that as I'd quite forgotten RCM had discussed this topic.
|
|
|
|
|
In Java I use the log.Log(Level.type, message) and
In C# I use the log.LogWarning(message) or another.
I find it pretty annoying in Java. They clearly made this better choice - better choice in relation to design e.g extensibility and maintainability. However, I need to work more with the Editor when writing this (more choices and Level import).
In this case I would do as Java does, but also add most common usages e.g. LogDebug, LogWarning, LogError, etc.
I guess it also is worth to consider how many options the enum will represent. The answer to this question might not be the same for "small" enums and "large" enums.
I like this question btw.
Another question, is whether to use enums or classes as arguments, but ... that is another question
|
|
|
|
|
Thanks for sharing your experience using both approaches in two different environments.
Keld Ølykke wrote: I find it pretty annoying in Java. They clearly made this better choice... These two statements seem to conflict with each other. If the one approach is "pretty annoying" is it really "better?" And this is reason I raise the question: I have the same conflict internally. Which approach is "better" seems to come down to where you approach the problem from. One day I look at the problem from one perspective and one way seems "better." The next day I look at the code and say "How crappy! This way is better!" What I optimize for changes the context enough to change the answer.
Keld Ølykke wrote: Another question, is whether to use enums or classes as arguments, but ... that is another question Yes. Yes it is.
|
|
|
|
|
I'm looking for a CMS (Umbraco) doc type etc. structure for agile (mostly) project collaboration and eventually management. My initial idea is for a content type structure as follows:
Project Home
Project Area
Feature
Documents like overview and description, as well as miscellaneous artefacts.
User stories, Use Cases, Narative specs, etc.
Unclassified Project Documents, with attachements etc.
Then, for the User Stories, I integrate with YouTrack for fine grained, micro-tracking and developer assignment. Time tracking as well, that aggregates up to the Feature (or Story) on Umbraco.
That's my basic prototype. Any suggestions, warnings, anecdotes, or any other feedback would be great. This is a first iteration before demo'ing to the boss and team, and Umbraco is fairly flexible if not too customised.
|
|
|
|
|
|
The fourth result in that list is my duplicate of this question on StackOverflow. The range of results is simply too broad. I am looking for feedback from people who have implemented such a structure, particularly on Umbraco.
|
|
|
|
|
I am editing this post to remove the sample code as I no longer think it would be a good design.
After more research, it appears that the Data Access Object Design Pattern is a good solution to separate a Data Access API from the business objects.
Example: http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm
Comments are welcome.
Thanks!
Carlos.
Original Question: What is the best Design Pattern to separate data access from the business layer?
modified 14-Feb-14 12:03pm.
|
|
|
|
|
Why is it necessary to separate the data layer from the business layer? Are you thinking of changing the data repository? Is there another reason?
|
|
|
|
|
Just to counter the other inference in the other response there are good reasons for having a data layer.
It helps to start with a data model. A data model represents data in the application and although it will often be one to one with database tables/objects that isn't always the case.
Once you have that then your data base layer is created to expose that data model.
This is common enough that there are already generic frameworks for it. NHibernate is one and there are others.
In my experience it is a bad idea to use inheritance as you have suggested. Data models seldom represent inheritance and implementing it like that even when it seems like such models are there is often a problem. This of course is compounded by a poor design where inheritance is used rather than a better choice of attributes and/or composition.
You data layer should not expose anything about the database itself. Often it will be better to have helper classes that do the real work and your exposed classes use those to do the real work.
|
|
|
|
|
Carlos Merighe wrote: ANY COMMENTS OR SUGGESTIONS? STOP SHOUTING!
Carlos Merighe wrote: PLEASE BE SPECIFIC. STOP POSTING TEXT IN ALL-CAPS!
You weren't specific with wich type of comment you expected, so my apologies, I'm grumpy, ignore it if you're not in a good mood.
What's the difference between Oracle and SQL? Does Oracle not use SQL? Did you mean "SQL Server" or "MySQL"?
Second, you don't want two different implementations to load data from a DataProvider that shares an interface; one can handle both scenario's using a db-agnostic interface (the IDbCommands) - there may be variations in the queries, but the infrastructure would be the same. Any ORM worth it's money would provide the same functionality. ORM's are sweet, they keep code nicely readable.
Alternatively, if you want to dive into some examples created from your dataset - take a look at some code-generators like MyGeneration[^]; there's usually multiple templates to create 3-tier applications (and more) - some templates generating complete websites. A benefit is that the code is generated from data that you're (often) familiar with, making it easier to recognize some of the parts (compared to those abstract examples in the books).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|