Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

query on c#4 interfaces

Posted on 2012-03-20
3
Medium Priority
?
388 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 2000 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 41

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

783 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