none
Confused by terminology used in the documentation RRS feed

  • Question

  • I'm very confused on the usage choice for the term "implementation" in the following documentation:

    https://msdn.microsoft.com/en-us/library/zcx1eb1e%28v=vs.110%29.aspx#

    Specifically, these lines of text:

    • "Although a class generally includes both definition and implementation (unlike interfaces, for example, which contain only definition without implementation), it can have one or more members that have no implementation."
    • "Class members that have no implementation are abstract members."
    • "A class can implement any number of interfaces,..."

     

    I find this to be a very confusing. What does it mean that a Class, Class Member, or Interface has or does not have an implementation?

    It first states that "interfaces...contain only definition without implementation", then states that "A class can implement any number of interfaces,...".

    How can you implement something that has no implementation?

    To clarify, I understand that if you have any Class members that have no implementation that they are considered to be "abstract" and that any Class with abstract members is, itself, considered an abstract class.

    How do I recognize "Class members that have no implementation" from any other class member in order to figure out if it is an "abstract member" in the first place?

    Having said that, I am confused by this statement in the documentation for abstract classes:

    https://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396

    • "Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented."

    If not for the second part of the second sentence, I would have thought that to have no implementation means to not be able to instantiate it. With the second part of the sentence, I have no clue what any of this means.





    • Edited by Platoxia Friday, October 23, 2015 2:04 PM
    Friday, October 23, 2015 1:06 PM

Answers

  • Hi Platoxia,

    You need to first understand what is Interface in C#. Implement means like writing down the logics in your code. Please read the below article which explains what is Interface.

    Interface Tutorial

    A good example: Interfaces in C# (For Beginners)

    Also see the below example: 

    It has a class called HelloService.cs where when user type some string it just "Hello" before it. Example: Hello Interface

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace HelloService
    {    
        public class HelloService : IHelloService
        {
    
            public string GetMessage(string name)
            {
                return "Hello" + name;
            }
        }
    }
    


    And below is an Interface class called IHelloService.cs. Which is exposed to the world. That means instead of exposing the above code where main logic is implemented you just create an Interface where this Interface is linked up with the main class where the logic is implemented.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace HelloService
    {   
        [ServiceContract]
        public interface IHelloService
        {
            [OperationContract]
            string GetMessage(string name);
        }
    }
    

    You see in the above code this HelloService : IHelloService its mean that (Implementation:Interface) On the Right side of ":" (colon) is the access point and left side is implementation.

    So instead of accessing/ exposing the GetMessage() method directly, user has to call the interface IHelloService and access the method via it. That way It provide more security.

    Example: A power station produces a power. In order to access that power you to connect plug to power socket in your home not just directly go to power station and access it. So they just expose a power socket to your home to access their produce power.

    Hope this explains to you

    Thanks,

    Sabah Shariq



    • Proposed as answer by Sabah ShariqMVP Friday, October 23, 2015 1:23 PM
    • Edited by Sabah ShariqMVP Friday, October 23, 2015 2:00 PM
    • Marked as answer by Platoxia Friday, October 23, 2015 4:01 PM
    Friday, October 23, 2015 1:18 PM
  • Hi Platoxia,

    I think you are mixing the concept.

    "Implementation" just means written. When you're talking about abstract classes and interfaces, you're talking about writing the parts that you need to write because you inherited that class or said that you're implementing that interface.

    Abstract methods and interfaces are different forms of the same kind of the thing: they're a set of methods (and maybe other things, but let's go with methods for now) that someone will actually need to write. You're saying "when someone inherits this class or implements this interface, they must implement (write) this method."

    Example: Let's say you're writing some banking software. You have a BankAccount class. How do you calculate interest on a bank account? Well, it depends on the kind of account. You can't really have "just a bank account" at our bank: you can have a passport savings account, a gold savings account, a silver checking account, etc. But all BankAccounts need to know how to calculate interest. So BankAccount could be an abstract class with CalculateInterest as an abstact method.

    When you write the SilverCheckingAccount class (which is a specific type of BankAccount), you'll need to write the CalculateInterest method for the class. That's "implementing" it.

    Thanks,

    Sabah Shariq


    • Edited by Sabah ShariqMVP Friday, October 23, 2015 2:41 PM
    • Marked as answer by Platoxia Friday, October 23, 2015 4:00 PM
    Friday, October 23, 2015 2:31 PM
  • I think we each speaking about this in different contexts, Sabah.

    I am speaking about this in the context of a high level overview of Classes as they pertain to .NET specifically, as found in the .NET development guide; which is a high level, language agnostic view of the .NET framework.

    Is it possible for the following questions to be answered without delving into how to implement encapsulation in code?

    • What does it mean that a Class, Class Member, or Interface has or does not have an implementation?

    Is this simply a matter of it being defined as abstract?

    • How do I recognize "Classes or Class members that have no implementation" (other than having "abstract" written in front of its definition) from any other Class or Class member in order to figure out if it is an "abstract Class or Class member" in the first place?

    I suppose even at this point, my entire problem is the semantics of terminology. The use of "implementation" just seems completely wrong and is preventing me from understanding what is intended in the guide.

    Edit:

    To clarify, I understand about encapsulation and that abstract classes and interfaces define what derived classes or classes that use the interface should do (or have to do, depending on how they are defined).

    In the meantime I will go through the tutorial you posted. Perhaps I simply do not understand the context the .NET guide is written in.

    Edit 2:

    Okay, I'm going to go with "implementation" as meaning "statements", where "statements" means executable code. I understand that Abstract Classes and Interfaces have no "implementation" in that they do nothing but define what derived classes or classes that use the interface must include.

    For the record, I still think the use of "implementation" is a bad choice of terminology in the context it is being used in the .NET guide. Especially given the fact that "implement" is being used in the proper, grammatical, context together with "implementation" that is being used in an entirely different context.


    Thank you for your time Sabah. Reading your replies helped me with the context.


    • Marked as answer by Platoxia Friday, October 23, 2015 4:00 PM
    • Edited by Platoxia Friday, October 23, 2015 4:05 PM
    Friday, October 23, 2015 3:16 PM

All replies

  • Hi Platoxia,

    You need to first understand what is Interface in C#. Implement means like writing down the logics in your code. Please read the below article which explains what is Interface.

    Interface Tutorial

    A good example: Interfaces in C# (For Beginners)

    Also see the below example: 

    It has a class called HelloService.cs where when user type some string it just "Hello" before it. Example: Hello Interface

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace HelloService
    {    
        public class HelloService : IHelloService
        {
    
            public string GetMessage(string name)
            {
                return "Hello" + name;
            }
        }
    }
    


    And below is an Interface class called IHelloService.cs. Which is exposed to the world. That means instead of exposing the above code where main logic is implemented you just create an Interface where this Interface is linked up with the main class where the logic is implemented.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace HelloService
    {   
        [ServiceContract]
        public interface IHelloService
        {
            [OperationContract]
            string GetMessage(string name);
        }
    }
    

    You see in the above code this HelloService : IHelloService its mean that (Implementation:Interface) On the Right side of ":" (colon) is the access point and left side is implementation.

    So instead of accessing/ exposing the GetMessage() method directly, user has to call the interface IHelloService and access the method via it. That way It provide more security.

    Example: A power station produces a power. In order to access that power you to connect plug to power socket in your home not just directly go to power station and access it. So they just expose a power socket to your home to access their produce power.

    Hope this explains to you

    Thanks,

    Sabah Shariq



    • Proposed as answer by Sabah ShariqMVP Friday, October 23, 2015 1:23 PM
    • Edited by Sabah ShariqMVP Friday, October 23, 2015 2:00 PM
    • Marked as answer by Platoxia Friday, October 23, 2015 4:01 PM
    Friday, October 23, 2015 1:18 PM
  • Implement means like writing down the logics in your code.

    Thanks,

    Sabah Shariq


    If I am incorrect please correct me but I think the word you are looking for here is "statements".

    If this is the case, then "implementation" should be changed to "statements" in the documentation as follows:

    • "Although a class generally includes both definition and statements (unlike interfaces, for example, which contain only definition without statements), it can have one or more members that have no statements."
    • "Class members that have no statements are abstract members."
    • "A class can implement any number of interfaces,..."

    And...

    • "Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and frequently either have some statements, or have no statements at all."

    Does this change the meaning of the original text or does it clarify it?



    • Edited by Platoxia Friday, October 23, 2015 2:15 PM
    Friday, October 23, 2015 1:58 PM
  • Hi Platoxia,

    I think you are mixing the concept.

    "Implementation" just means written. When you're talking about abstract classes and interfaces, you're talking about writing the parts that you need to write because you inherited that class or said that you're implementing that interface.

    Abstract methods and interfaces are different forms of the same kind of the thing: they're a set of methods (and maybe other things, but let's go with methods for now) that someone will actually need to write. You're saying "when someone inherits this class or implements this interface, they must implement (write) this method."

    Example: Let's say you're writing some banking software. You have a BankAccount class. How do you calculate interest on a bank account? Well, it depends on the kind of account. You can't really have "just a bank account" at our bank: you can have a passport savings account, a gold savings account, a silver checking account, etc. But all BankAccounts need to know how to calculate interest. So BankAccount could be an abstract class with CalculateInterest as an abstact method.

    When you write the SilverCheckingAccount class (which is a specific type of BankAccount), you'll need to write the CalculateInterest method for the class. That's "implementing" it.

    Thanks,

    Sabah Shariq


    • Edited by Sabah ShariqMVP Friday, October 23, 2015 2:41 PM
    • Marked as answer by Platoxia Friday, October 23, 2015 4:00 PM
    Friday, October 23, 2015 2:31 PM
  • I think we each speaking about this in different contexts, Sabah.

    I am speaking about this in the context of a high level overview of Classes as they pertain to .NET specifically, as found in the .NET development guide; which is a high level, language agnostic view of the .NET framework.

    Is it possible for the following questions to be answered without delving into how to implement encapsulation in code?

    • What does it mean that a Class, Class Member, or Interface has or does not have an implementation?

    Is this simply a matter of it being defined as abstract?

    • How do I recognize "Classes or Class members that have no implementation" (other than having "abstract" written in front of its definition) from any other Class or Class member in order to figure out if it is an "abstract Class or Class member" in the first place?

    I suppose even at this point, my entire problem is the semantics of terminology. The use of "implementation" just seems completely wrong and is preventing me from understanding what is intended in the guide.

    Edit:

    To clarify, I understand about encapsulation and that abstract classes and interfaces define what derived classes or classes that use the interface should do (or have to do, depending on how they are defined).

    In the meantime I will go through the tutorial you posted. Perhaps I simply do not understand the context the .NET guide is written in.

    Edit 2:

    Okay, I'm going to go with "implementation" as meaning "statements", where "statements" means executable code. I understand that Abstract Classes and Interfaces have no "implementation" in that they do nothing but define what derived classes or classes that use the interface must include.

    For the record, I still think the use of "implementation" is a bad choice of terminology in the context it is being used in the .NET guide. Especially given the fact that "implement" is being used in the proper, grammatical, context together with "implementation" that is being used in an entirely different context.


    Thank you for your time Sabah. Reading your replies helped me with the context.


    • Marked as answer by Platoxia Friday, October 23, 2015 4:00 PM
    • Edited by Platoxia Friday, October 23, 2015 4:05 PM
    Friday, October 23, 2015 3:16 PM