Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Guys,

The question belongs to .NET but, I need to analyze number of applications where I can use it. Because .Net People may not know because .NET does not support Multiple inheritance. But this is something different than multiple inheritance. Please suggest the real time applications where I can use this concepts.

The question is - if it possible. Please don't say that this is not possible in .NET.

I am just giving a basic concept, please think it in deep.

Let me proceed right away,

Let's assume the following classes,

public class A
{
    public string PropA { get; set; }

    public void MethodOfA()
    {
        Console.WriteLine("Calling MethodOfA from A");
    }

    public void MethodOfB()
    {
        Console.WriteLine("Calling MethodOfB from A");
    }
}

public class B
{
    public string PropA { get; set; }

    public string PropB { get; set; }

    public void MethodOfA()
    {
        Console.WriteLine("Calling MethodOfA from B");
    }
}

public class C : A, B
{

}


Class C is derived from A and B classes

Now, class A and B both contains a common method MethodOfA()

So, when I say

 Collapse
C c = new C();
c.MethodOfA();


It calls MethodOfA() from A and then it calls MethodOfA from B sequentially.

And the output will be

Calling MethodOfA from A
Calling MethodOfA from B

Now, when I say

 Collapse
C c = new C();
c.A.MethodOfA();


It calls method of A only and same for B class.

And the output will be

Calling MethodOfA from A

So, I can call method in a row at one shot or I can call it by class name.

Same thing we can apply for the properties too.

We can set properties at one shot or we can get property at one shot.

We can set property by a class name or we can get property by a class name.
Posted
Updated 13-May-11 17:23pm
v3
Comments
Sergey Alexandrovich Kryukov 13-May-11 23:25pm    
"Analyze number of applications"? -- already interesting...
"Please don't say that this is not possible in .NET." -- I won't -- my promise :-)
What did you drink?
--SA
Sanjay J Patolia 14-May-11 4:28am    
I have written "Please don't say that this is not possible in .NET." that because people gives only one answer that it is not possible in .NET. So, except that one, we may go on to think. There was no other intense. Thank You :)
Sergey Alexandrovich Kryukov 16-May-11 3:48am    
By this request you cannot make the impossible possible. If someone mistakenly thinks something is impossible while in fact it is possible, you cannot fix it by such request. Also, don't forget that you can mistakenly think that something is possible while if fact it is not. So, you should agree such request is practically useless. Just be logical.
--SA

1 solution

After reading all of that I'm not sure what the actual question is, you have a concept for some design pattern and you want us to think of something to use it in?

I honestly can't think of anything I'd really need to do this with.

It is possible to do using interfaces and a negligible amount of effort, but it seems more like something you'd do for a specific problem rather than a generic pattern you'd want to apply for many things.
 
Share this answer
 
Comments
Sanjay J Patolia 14-May-11 4:05am    
As you said,

After reading all of that I'm not sure what the actual question is, you have a concept for some design pattern and you want us to think of something to use it in?

Yes you are right.

Secondly, you said that using interfaces but the problem in interface is we have to implemnent all the methods in a class not in interface so a class which implements that interface has to write an implementation for those methods in a class only.

So that's it. I hope you are geting it. Thank You :)
Sergey Alexandrovich Kryukov 16-May-11 3:50am    
What a fruitless conversation, guys!
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900