Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is concrete implementation?

Tags:

.net

wcf

I saw lot of posts in StackOverflow and elsewhere talking about concrete implementation. While fiddling with WCF i came through the line

Tying your service implementation, or any “service based” class to a concrete implementation is never a good idea.

Can anyone explain what Concrete Implementation is?

like image 519
NLV Avatar asked Jun 23 '10 09:06

NLV


People also ask

What is concrete implementation in Java?

A concrete class is a class that has an implementation for all of its methods. They cannot have any unimplemented methods. It can also extend an abstract class or implement an interface as long as it implements all their methods. It is a complete class and can be instantiated.

What is concrete method?

A concrete method means, the method has complete definition but it can be overridden in the inherited class. If we make this method "final" then it can not be overriden. Declaring a method or class "final" means its implementation is complete.

What is concrete class example?

A concrete class is complete. Because all of its methods are implemented, we call it a concrete class, and we can instantiate it: Car car = new Car(); Some examples of concrete classes from the JDK are HashMap, HashSet, ArrayList, and LinkedList.

What is concrete in C#?

A concrete class is a simple class with members such as methods and properties. The class describes the functionality of the objects that it can be used to instantiate. Often, when working with inheritance hierarchies, the least specialised base class cannot fully represent a real object.


2 Answers

It is implementation of something abstract (abstract class, interface). Note that you can instantiate only objects of concrete classes.

Just for example if you have :

abstract class AbstractClass
{
    .......
   // Here you have some abstract methods 
}

class ConcreteClass : AbstractClass
{
.......
}

In case of WCF it wants to say that although it is allowed to mark classes with ServiceContract attribute better to have it on separate Interface and implement that interface in concrete class marked with ServiceBehavior attribute.

Like this :

[ServiceContract(Namespace = "MyNamespaceName")]
interface IMyInterface
{
    [OperationContract]
    int SomeMethod(.....);

   ......    
   ......    
}

[ServiceBehavior(......)]
public class SomethingConcrete : IMyInterface
{
    // implementation of SomeMethod
}
like image 92
Incognito Avatar answered Sep 20 '22 09:09

Incognito


If you have an interface or abstract class, it need to be implemented.

A class that implements such an interface or class is called a concrete implementation (because only such an implemented class can be instantiated).

The principle stated means that you shouldn't code against the concrete implementation directly, as you may want to swap it for another concrete implementation at a later time without changing your code. This means you should use interface and abstract class references instead of concrete implementations.

like image 20
Oded Avatar answered Sep 23 '22 09:09

Oded