Solved

query on c#4 interfaces

Posted on 2012-03-20
3
332 Views
Last Modified: 2012-08-13
I have just been reading:
http://www.daniweb.com/software-development/csharp/threads/114364

At the bottom is the following:

Interface in object answer to one simple requirement facilitate mostly used functionality
you whant to give only what is use full to the user so using your object become simpler
if your class offer 40 functionality and one of your user commonly uses 3 of theme you dont whant to show him all of them it create noise. take an oo course.

Say for argument sake I did have a class with 40 functions on and only wanted to expose 3.

Is it the case that I need to create an interface that only has 3 function declarations and then create a new class which implements that interface or....?

Wouldn;t that mean ending up with a lot of sub version of the main class?

Excuse the stupid question still trying to get using interfaces straight in my head.

Thanks
0
Comment
Question by:scm0sml
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37742979
I don't know that I necessarily agree with using interfaces for the sole purpose of member hiding--though I suppose you could. An interface is really more like a contract. You are telling other code:  "Hey, I offer you these services and/or data." Using interfaces is also a way to get around .NET's single-inheritance behavior--you can inherit only one class, but you can implement n interfaces.

To answer your specific question, yes, you would create the interface that only has the 3 methods. This doesn't really hide anything, though. If I know the type of the object implementing the interface, then I can simply cast the object to that type and voila!, I have access to the public members again.
0
 

Author Comment

by:scm0sml
ID: 37743006
Right ok great thanks for that.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37743011
some good articles:
http://www.4guysfromrolla.com/articles/110304-1.aspx

http://msdn.microsoft.com/en-us/library/ms229013.aspx

In terms of hiding code I would make the 3 public and the rest private . . . no need to create an interface for that.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question