Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,914 members, 7,802,976 topics. Date: Saturday, 20 April 2024 at 06:13 AM

Abstract, Interface And Adapter Classes - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Abstract, Interface And Adapter Classes (3454 Views)

User Interface Design For The Beginning Web Programmmer / Bespoke Digital Media: How To Inherit Child Interface Abstract Methods ? / Processing Games And Tangible User Interface (2) (3) (4)

(1) (Reply) (Go Down)

Abstract, Interface And Adapter Classes by csharpjava(m): 10:57am On May 16, 2011
For those that are interested in this information:

An Abstract Class - Does not allow you to create objects, you can only inherit from an Abstract Class and you must use all the Abstract methods in an Abstract Class in the class that inherits from it.

Interface - Is a class that only contains Abstract Methods, with no Attributes or Fields and you must use all the Abstract methods in an Interface when you implement it. It allows you to borrow from more than one class, by using the the word "implements" followed by a comma if using more than one interface Eg: public class SomeClass extends JFrame implements ActionListener, Shape - to as many as you want.

[size=16pt]An Adapter Class - Allows us to use 419 grin when using an interface[/size]

Abstract and Interface classes allow programmers to write applications that can work with each other. Eg: The software in a keyboard has an interface that allows it to work with the software in the monitor in order to display the characters on the screen.
Re: Abstract, Interface And Adapter Classes by Otuabaroku: 11:56am On May 16, 2011
@csharpjava , thank you for the explanation. From what you have explained, it seem to me they both have the same function and similar. The big question now is why should I use interface instead of abstract class or why should I use abstract instead of interface. Are there some occasion where abstract is better to use or are there some occasion where interface are better to use. What would inform your opinion when choosing between the two?
Re: Abstract, Interface And Adapter Classes by csharpjava(m): 1:13pm On May 16, 2011
Otuabaroku

@csharpjava , thank you for the explanation. From what you have explained, it seem to me they both have the same function and similar. The big question now is why should I use interface instead of abstract class or why should I use abstract instead of interface. Are there some occasion where abstract is better to use or are there some occasion where interface are better to use. What would inform your opinion when choosing between the two?

In Java and similar languages you cannot inherit more than one class so if you need to inherit more than one class then you'll need to create an interface. See example below on how to inherit one class and implement more than one interface:

public class SomeClass extends JFrame implements ActionListener, Shape
Re: Abstract, Interface And Adapter Classes by wassolldas: 2:22pm On May 16, 2011
An interface is a contract that a class pledges to fulfill. A specification of methods that any implementing class promises to provide functionality for.
Re: Abstract, Interface And Adapter Classes by wassolldas: 2:54pm On May 16, 2011
An Adapter is a design pattern. The simplest example I can think of at the moment is - Consider an electric outlet with the three outputs type used in Nigeria. if you buy an electrical component from a country that has a different input format from that used in Nigeria, you will need an Adapter to make sure the new device works with the existing outlet.

Similarly if you have an existing library that provides a correctly working implementation and you get a new class or library that needs to work together with what you have on ground, the Adapter design pattern comes in handy to provide an interface between the two libraries or classes.

ExistingClass - existingMethods  communicates with NewClass - newMethods by using an Adapter class. The Adapter class takes the method of the existing classes and modifies the output into the format understood by the new class.
Re: Abstract, Interface And Adapter Classes by Otuabaroku: 5:24pm On May 16, 2011
Thank you guys, it was helpful.
Re: Abstract, Interface And Adapter Classes by candylips(m): 8:45pm On May 16, 2011
When will u use abstract class instead or interface and vice versa
Re: Abstract, Interface And Adapter Classes by csharpjava(m): 8:58pm On May 16, 2011

When will u use abstract class instead or interface and vice versa
When you need multiple inheritance from Abstact Classes in a language like Java that does not support multiple inheritance, then you'll need to use an interface.

C++ allows multiple inheritance but you must be sure you know what you are doing.
Re: Abstract, Interface And Adapter Classes by Seun(m): 1:02pm On May 17, 2011
Yep. Faced the same issue in Scala.
Re: Abstract, Interface And Adapter Classes by SayoMarvel(m): 11:51pm On May 17, 2011
Multiple inheritance can be a real pain in the a**, no wonder its not supported in Java.
Re: Abstract, Interface And Adapter Classes by candylips(m): 10:48pm On May 18, 2011
code with multiple interface inheritance can be nasty as well. sometimes u see code with an interface hierarchy running 10 interfaces deep
Re: Abstract, Interface And Adapter Classes by csharpjava(m): 12:13am On May 19, 2011
candylips

code with multiple interface inheritance can be nasty as well. sometimes u see code with an interface hierarchy running 10 interfaces deep

With multiple interface inheritance the methods are blank, the compiler will only use the methods you write in your class. But with multiple inheritance if there are two methods with the same name in the classes inherited and you do not sort this out in your class the compiller will pick anyone for you, this can lead to a serious bug in your program.

Let me know if there are issues I have not covered regarding nested interface inheritance.
Re: Abstract, Interface And Adapter Classes by Otuabaroku: 10:26am On May 19, 2011
Just thinking aloud ;is there any possible issue developing Mail application with RMI instead of SMTP in javamail API?
Re: Abstract, Interface And Adapter Classes by csharpjava(m): 11:45am On May 19, 2011
Just thinking aloud ;is there  any possible issue developing Mail application with RMI instead of SMTP in javamail API?

Try it with RMI and let us have the results of your Thinking Aloud Protocols so that we can analyse them here.
Re: Abstract, Interface And Adapter Classes by Otuabaroku: 9:33am On May 21, 2011
csharpjava:

Try it with RMI and let us have the results of your Thinking Aloud Protocols so that we can analyse them here.
You did not try at all. Why should you advise me to try it, when you know that it has an obvious short coming.
Re: Abstract, Interface And Adapter Classes by csharpjava(m): 11:19am On May 21, 2011
Otuabaroku

You did not try at all. Why should you advise me to try it, when you know that it has an obvious short coming.

I have not tried it yet. Have you? If yes what were the issues found?
Re: Abstract, Interface And Adapter Classes by Otuabaroku: 1:00pm On May 22, 2011
csharpjava:

Otuabaroku

I have not tried it yet. Have you? If yes what were the issues found?

Ok bros, was just frustrated when the result I anticipated was not coming readily and I bombed into " In case of RMI or Client/Server programming, the applications wait for a reply after sending a request, which affects the performance of the application". However, I have accomplished my objective with Javamail API. Thank you for your concern.

(1) (Reply)

Results For Programming Challenge Season 2 / Nigeria's Own Facebook(social Network) / Web Design Training On Whatsapp:

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.