It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Interface should be used when none of the implementation details are available to the current scope of the code.
Abstracts should be used when some of the implementation details are available to you.
Query - Why still these terms are required? Why can't Business objects directly communicate with DataAccess.SqlServer Layer?
Interface should be used when none of the implementation details are
available to the current scope of the code.
Not really. What you're referring to is encapsulation. There is the concept of "information expert." Only the class that knows how to do something should be the one doing it. Interfaces are used for polymorphism and decoupling. When consuming code wants to treat certain types of objects the same way, that code can use all of those objects the same way by treating them as the interface type.
Abstracts should be used when some of the implementation details are
available to you
I'm not sure what you mean here. I think you're confused because this doesn't sound right. Abstract classes are used the same way interfaces are, except that they're allowed to have implementation in them.
Query - Why still these terms are required? Why can't Business objects
directly communicate with DataAccess.SqlServer Layer?
They can, but at the cost of maintainability, flexibility, and testability. If you want to replace your data layer with another, you can't because the consuming code has a direct dependency on the current data layer. If you want to unit test your logic, you can't without hitting the DB. If you put your database classes behind an interface, you could mock the data layer in unit testing and test your logic classes without hitting the database.
Very Short Example
public Foo FooLogic
{
IFooData fooData = DataAccessFactory.GetDataClass<IFooData>();
return fooData.GetFoo();
}
Now your logic class isn't tied to a particular data class. The factory can return a real FooData implementation, or it can return a mock data object, or a new data access layer can be put in place without affecting the code in the logic class.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an utility library with the class ConsoleApp, which has only static method like GetIntValue(string name) to ask user to enter the integer value of the parameter with specified name, or functions to parse command line parameters.
As for me ConsoleApp is an utility class, and inheriting it just to get avoid "ConsoleApp." in the code looks like BaseBeen anti-pattern.
But on the other side, ConsoleApp will be inherited only by the classes that is really Console applications, in this way, it's not a BaseBeen.
So, is it really BaseBeen?
SOLID design principles (particularly SRP, O/CP, and DIP) suggest that you're better providing that functionality via delegation (e.g. strategy pattern). Has-A is better than Is-A, etc.
However, you're pretty squarely in first-world-problems territory here because Program.cs is very much on the transient end of your codebase. Clearly you might need to parse some command line parameters before your bootstrapper runs (e.g. to configure your bootstrapper!), so you might find it challenging to inject some kind of value provider.
So, I'd say yes it's an antipattern, however there are probably more important things to worry about.
See e.g. http://s3.amazonaws.com/hanselminutes/hanselminutes_0145.pdf page 8 where Uncle Bob talks about DIP:-
"Main is the most concrete of our
functions and it will create all of our instances and all of the
factories ... and it will then
hand off to the abstract part ... and the
abstract core will manipulate it as though it were in this fantasy
world where everything was abstract."
If Main has to call some static methods, that's ok. If you want to inherit from a utility class to make it easier for you, that maybe smells a bit but I don't really care. Just make sure you know where the boundary is. If you're using your static utility class outside of Main then you're likely to have a problem.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Can someone please explain which part of the provider model best represents the business layer?
Where should the business rules and business logic live?
If you mean something like the Membership Provider in .net, I would say the Business Layer uses the providers as a service (like John states). Though the line is a little gray if you are implementing providers yourself (like is a user a business object? if so what about the rules in the provider logic?).
Typically providers are developed separately from business applications because they are more infrastructure type code.
However, if you are just interested in the provider portion then, you typically have the following parts in a provider:
1. infrastructure stuff (config reading/database communication/etc)
2. provider interface (provides the service to consuming code)
3. 'business' objects and rules
I guess the business layer would be the implementation of the specific provider (there is usually a base class that implements the infrastructure stuff). For instance the membership provider deals with user and membership objects and has a few rules on how to do what it does as a provider.
Unless you're talking about a different "provider model" than I am, there is no relationship to a business layer.
A provider model is simply an architecture where one or more components provides a set of services. For instance, in LINQ, a LINQ Provider provides the mapping to a data store or other source of data, while the .NET Framework classes provide the rest.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using simple 3 tier architecture.
In this I am using DTO classes to communicate between UI,BL and DL.
So there is any better way for communication between layers? or this is the right way?
DTO, Data transfer Object, is the concept for distribution layer, you use when transferring data between your consumers and your service. So, if you don't publish any service, get off DTO.
To answer your question, it also depends on how complex your application is. If it's simple, just use CRUD operation, or you can even use DataTable, DataSet for communication.
Otherwise, Domain Entity from DDD is the core object for communication between layers: Data Access Layer, Business Logic Layer and Presentation Layer.
Basically, there are some different type of objects in application:
DTO, use when you public services, main object to communicate between consumer and your service.
View Model, object in presentation layer to support UI.
Domain Entity is from Business logic layer to contain business logic.
Be careful with the term:
Tier: it means physical, like database server, web server.
Layer: it means logical layer: Persentation Layer, Business Logic Layer, Data Access Layer.
Read this tutorial it is very informative. It will help you to decide is DTO right for your scenario.
In addition to #Talha's answer, I'd recommend this article. It is EF-oriented, but concepts, described there, are common ones.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
What is the use of interface in projects except the use of loosely coupling?
Does it reduce memory usage while passing it as argument?
Please list the advandages deeply.
I think you should have look to oop example and specially Design pattern whihc help you to understand why to use interface..
Another important advantage to programming to interfaces is that it provides a means for polymorphism. If I have a collection of IShape and IShape provides a CalculateArea() method, I can supply a new shape to the project by adding a new implementation of IShape. So, yes, this is providing looser coupling by virtue of adhering to the open/closed principle. But, it's also allowing IShape to be treated abstractly by clients without needing to know which specific IShape it is.
Polymorphism is fundamental to object oriented design, and an interface is a way to achieve that (the other being inheritance).
I'd also throw in that interface implementation tends to be expressive in terms of code intentions. If I have some declaration like:
public class Foo : IDisposable, IPersistMyselfToDisk, IRaiseUpdateEvents
I can tell a lot about the class and what it does at a glance -- more so than I could if I simply buried that functionality somewhere in the details of the class. Again, this goes back to decoupling to some degree, but it stands on its own as well.
I think you're going to find that decoupling is wrapped up with just about all advantages of using interfaces since providing classes that are cohesive and loosely coupled is just about as fundamental to OOP as having classes with state and behavior.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In my interview i was aked that give some realtime scenario where you can implement interface.. write some code also.
They want to ask we have abstract methods then why do we need interface... write some code.
Thanks in Advance
Read this great documentation in MSDN:
Recommendations for Abstract Classes vs. Interfaces
Abstract Class versus Interface from Codeproject.com with sample code too.
Hope it helps!
As MSDN shows
If you anticipate creating multiple versions of your component,create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
Because you can implement as many interfaces as you want. with an abstract class you can only inherit from one.