In OOP why would you even want to use an interface?

1 Answer

Answer :

Because you can then indicate things like this method takes an argument, which can be of any class that implements this interface. It’s not for the benefit of the classes that implement it, but the code that uses those classes. For instance, one way to build an object-relational mapper in PHP might be to create an interface that all storable objects had to implement. You could then build your class hierarchy ignoring the fact that they’re all storable in your database, and put all the code relating to database access in the methods declared by the interface. This way, if there is some object that shouldn’t be stored in the database, or that requires special handling before going into the database, the code will still conform to the interface even if it doesn’t have the same implementation. You can see this pattern in Apple’s Cocoa framework: there’s an interface called NSCoding that declares the methods necessary to serialize an object. User-created objects that conform to the NSCoding interface and implement the necessary methods can be saved to and loaded from files without any extra work on the part of the programmer. The other principal way to do this is multiple inheritance, which causes a lot of problems. And the reason this is a good thing is because having isolated bits of code that communicate with each other through well-defined interfaces (in the generic sense) leads to more maintainable code. Instead of knowing how the other chunk of code actually works, you just know that if you call this function with these arguments, this other thing will happen. Interfaces (in this specific sense) are a way of formalizing the contract between the caller and the called code.

Related questions

Description : What programming languages should I learn if I am interested in user interface design?

Last Answer : You need to be more specific. Are you interested in Mac, Windows, Linux, or Web based stuff?

Description : I want to make a video games, where do I start?

Last Answer : answer:This may sound vague, but yes, and then some. Seriously, you need a WIDE range of skills to make video games. A wide enough range that most games are made by teams as it's extremely rare to ... , I'd say the best place to start is the concept, followed by the design, then assembling a team.

Description : I want to start a site like ebay. (not another one!) How should I proceed?

Last Answer : answer:Sweet holy moly, How much would it cost? (in dollars and if I were to hire an American designer?) I think that would greatly be influenced if you go through a freelance designer, a company, and the ... either. With the detail you do have that is about the best I can do for you at the moment.

Description : Want to expand on my marketability as a web developer. What language should I learn?

Last Answer : answer:Recently discussed here: http://www.ask-public.com/disc/2804/whats-the-best-web-programming-language-to-study-right-now/ I’ll answer again, since you already have php, i would look at ASP and Cold Fusion. I also don’t see much demand for Python or Ruby. Not they are bad languages.

Description : Want HTML code to enlarge text ?

Last Answer : HTML to enlarge text: your text or your text

Description : I want to make a question and answer site like mind. Domain and hosting are ready. Can anyone make it ? Don't build with WordPress. Ans Bangla should not be made in this way. Knock if there is anyone like that.

Last Answer : You can contract with the admin of this website. He can make you a site.

Last Answer : You Below Link From Of all HTML tags Details To know Can : https://html.com/tags/

Description : What is the full form of 'OOP' ? -How To ?

Last Answer : The full form of 'OOP' is Object Oriented Programming

Description : What is the full form of OOP ?

Last Answer : OOP 's full Object Oriented Programming.

Description : Classic OOP - Object Oriented programming can be traced back to a language called Simula, and in particular Simula 67, which was popular during the _____: a) 1930s b) 1960s c) 1950s d) None of These

Last Answer : b) 1960s

Description : OOP was practiced in the: a) 1970s b) 1980s c) 1960s d) None of These

Last Answer : b) 1980s

Description : OOP uses a different set of programming languages than old procedural programming languages such as: a) C b) Pascal c) Both of Above d) None of These

Last Answer : c) Both of Above

Description : Object Oriented Programming (OOP) is a _______philosophy: a) Network b) Design c) Data Type d) None of These

Last Answer : b) Design

Description : What is OOP?

Last Answer : A: Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods.

Description : OOP features are i) Increasing productivity ii) Reusability iii) Decreasing maintenance cost iv) High vulnerability A) 1,2 & 4 B) 1,2 & 3

Last Answer : B) 1,2 & 3

Description : How To Do An Alley Oop

Last Answer : How To Do An Alley Oop The alley oop is an offensive strategy in basketball that can send a crowd to their feet, cheering. It seems simple, but the truth is it's very challenging because it requires ... alley oop. It'll make your opponent cringe, it'll wow the crowd, and will make you proud.

Description : Explain any four concept of OOP.

Last Answer : Basic Concepts of Object Oriented Programming:  1. Objects Objects are the basic run time entities in an object-oriented system. They may represent a person, a place, a bank ... objects that communicate with each other. Objects communicate with one another by sending and receiving information.

Description : List any six characteristics of OOP. Also list any two OOP languages.

Last Answer : Characteristics of OOP: 1) Emphasis is on data rather than procedure. 2) Programs are divided into objects. 3) Data structures are designed such that they characterize the objects. 4) Functions that operate on the data of ... 4) C++ 5) Ada 6) Object Pascal 7) Turbo Pascal 8) Eiffel 9) Java

Description : Write any four benefits of OOP. 

Last Answer : Benefits of OOP: 1. We can eliminate redundant code and extend the use of existing classes. 2. We can build programs from the standard working modules that communicate with one another, ... interface descriptions with external systems much simpler. 10. Software complexity can be easily managed.

Description : State the difference between OOP and POP.

Last Answer : OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURE ORIENTED PROGRAMMING (POP) Focus is on data rather than procedure. Focus is on doing things (procedure). Programs are divided into multiple ... approach is used in C++ language. Procedure oriented approach is used in C language.

Description : Which one of the following OOP concepts enables reusability of components?  (1) Inheritance (2) Encapsulation (3) Polymorphism (4) All of the above 

Last Answer : 2. Encapsulation 

Description : Do you still use spaghetti code , like QBasic?

Last Answer : talljasperman Sorry I didn’t know that spaghetti code was a pejorative. My teacher called it that and I did not look it up.

Description : Regulating email use?

Last Answer : What Operating System are you using and do you use a Desktop client for email or a web-based client?

Description : Why use ASP.NET MVC 4 over just HttpHandlers with JQuery Ajax?

Last Answer : answer:I'm not familiar with asp.net, so I'm not sure what it gives you, but a common problem with a single-page app using a lot of jQuery is that it can quickly become unmanageable, especially if ... you other questions, I'm a fan of using only as much as you need and your approach sounds fine.

Description : What does the use of the # symbol mean in XML Document Type Definitions?

Last Answer : answer:

Description : How to use cron in ruby on rails (2.3.5). Please help?

Last Answer : answer:At the UNIX prompt, type man crontab and help documentation will appear. - Crontab is the interface you use to schedule jobs in cron. It launches a basic text editor - usually vi but anything you want - and you enter in one ... . 30 21 * * 3 /path/to/maintenance.sh # #---------------------

Description : Why should I use JavaScript Library if it may effect the performance of a web site?

Last Answer : You might want to check out some extremely lightweight Javascript libraries such as xui, zepto, or jQuery Mobile. However, 17KB should not be a huge concern on iOS and Android devices. On phones with ... .example.com or mobile.example.com with minimal CSS, small page size, and no Javascript at all.

Description : Do any other ask-public users use J (the programming language)?

Last Answer : answer:Interesting. How can it confuse experienced programmers, and how is this an awesome thing? Also, is this one of those languages great for mathematics and scientific computation?

Description : If I already know basic PHP/MySQL, what else should I learn to use Google App Engine?

Last Answer : answer:I am not an expert, I just started reading up on this myself, but here are a couple of starting points on data storage. Rather than a separately maintained SQL database, ... .com/appengine/articles/datastore/overview.html http://code.google.com/appengine/docs/python/datastore/overview.html

Description : Why do the majority of Python packages use urllib2 instead of httplib?

Last Answer : answer:urllib2 is closer to curl. It's closer to a real client-and for many of us, makes much more sense than doing 4 or 5 steps to request an url and read the response. httplib is a lower ... It is normally not used directly - the module urllib uses it to handle URLs that use HTTP and HTTPS.

Description : When to use stored procedure and when function in SQL Server 2008?

Last Answer : There’s no technically right answer here – I think I’d do the SP calling SP.

Description : Will using .NET 3.5 server side for a web site place any notable restrictions on what web browers can use the site?

Last Answer : .NET 3.5 VSTS feature won’t restrict you on any navigation features.VSTS is solely browser independent.You could publish your site on any browser, but you need to do some customization while using firefox.Some addin features are needed to make your Server side setup function properly.

Description : How does one use his mind to create a plan ?

Last Answer : By deconstructing a problem into smaller pieces. I think people intuitively write business rules in their head for all problems. They may not account for all the options, and they may only see the ... but in reality, problem solving comes in the form of deconstructing a problem into Yes/No format.

Description : Which Windows program to use to introduce 6 year old to programming? Best program to teach LOGO or BASIC with graphics?

Last Answer : Get an old machine and load DOS 6.1 on it.

Description : Does anyone use ELGG?

Last Answer : Have you tried using www.ning.com as an alternative. It's pretty simple to use and no coding knowledge is required. It's pretty simple to modify, but you can't change the layout all that much. ... all look a lot alike. I believe you can break the mold and handcode the template in HTML though.

Description : What Kind Of Preset Should I Use On Handbrake?

Last Answer : Honestly, just give it a shot and use whatever preset produces the results you like. You won't ruin your movie or delete your computer or anything. So try all of the ones you have access to ... , and compare the final results, then continue to use the preset that produces the results you like best.

Description : Can I use an RSS feed like this?

Last Answer : RSS is a pull technology, so you are relying on the client to refresh to get the update.

Description : Why would a programmer use spaces instead of tabs for indentation?

Last Answer : Because the programmer works with other programmers, some of whom have their editors set to expand tabs to 8 spaces, others of whom have their editors set to expand tabs to 4 spaces, and still others of whom ... use only spaces than it is to get everyone to agree on how wide a tab stop should be.

Description : Why not always use .Classes in CSS and skip #IDs alltogether?

Last Answer : answer:IDs allow you to identify a unique element whereas classes are used for specifying just that, classes of elements. Its an important distinction but I can see how it might seem that it isn't needed ... of the more advanced selectors in CSS you'll find that it goes way beyond classes and IDs.

Description : Can you use JavaScript to force-replace a particular image in the browser cache?

Last Answer : answer:I'm not sure about doing it in js but if you make it so that the image/stylesheet/javascript file in question has a unique string after the filename like '/images/header.jpg?somerandomstring', when ... the string. That way, whenever you deploy a new version, it'll have a new cache string.

Description : How can i use programming to eliminate static in an audio clip?

Last Answer : hmm, fastest thing i can come up with right now is audicity, it has a plugin for it if i remember correctly, you could give it a try

Description : What kinda of code commenting system do you use?

Last Answer : answer: I write bad code. Seriously, that is in stuff viewable be to public. And I comment the fuck out of everything.

Description : Should I use a domain like youstre.am, or mystre.am or will no one remember it?

Last Answer : I think it’s memorable and clever. Go for it.

Description : State the use of OF and DF flags of 8086 microprocessor.

Last Answer : Overflow Flag: This flag is set if an overflow occurs, i.e. if the result of a signed operation is large enough to be accommodated in destination register. Direction Flag: It selects either increment or decrement mode for DI &/or SI register during string instructions.

Description : Salesforce SDK uninstallation from XCode?

Last Answer : Too many variables – only you know your code, how it was written, and how extensible (or not) it was in the first place. I assume you have been to the Saleforce API and SDK pages.

Description : Is there a program where you can identify music in a specific website?

Last Answer : Need Answer

Description : What is a good programming language to make a multiple choice quiz?

Last Answer : Google classroom should work.

Description : Is there a website that shows all the English words, idioms, etc ever invented, including archaic, unofficial, and newest words that have just been invented?

Last Answer : The problem with such a lexicon would be that there have been a lot of slang, dialect, idioms, and unofficial words that 99% of people have never heard of. Besides that, the English language is ... pretty good vocabulary. Hopefully, someone will recommend some. I am unable to do this at the moment.

Description : How can I add HTML markup to this ajax result?

Last Answer : Need Answer

Description : Function or application allowing me to connect or disconnect wifi?

Last Answer : Some routers - Belkins and older Ciscos, had an app that would allow you to remotely-control your router from your phone. You didn't say what kind of router you have, so it's hard to guess. You can ... . Bottom line - you can do this easily if you have a wifi-based power switch and an app. example