Results 1 to 6 of 6
Thread: Abstraction and interfaces
- 11-17-2011, 08:32 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 28
- Rep Power
- 0
Abstraction and interfaces
Hey so I'm currently in a Java class at my university. We just got into abstract classes and methods and interfaces. I'm not quite grasping what these are and why/when they would be used. I kind of understand the Abstract class concept. From what I've read, it looks like they are used if you need a super class that you do not what any instances of. But why? I guess I'm just not understand these concepts.
- 11-17-2011, 08:50 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Abstraction and interfaces
Have you ever seen a bird? I haven't; I have seen sparrows and hummingbirds and eagles etc. granted, they all belong to the species 'bird', but they aren't 'birds'. The class 'bird' is the abstract super class and the hummingbirds etc. extend from that class; we can treat them as if they were birds an even say that 'they are' birds, but they're more than just that.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-17-2011, 09:08 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 28
- Rep Power
- 0
Re: Abstraction and interfaces
Ok and interfaces? Are they the same thing?
- 11-17-2011, 09:24 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Abstraction and interfaces
Nope, an interface is more like a 'flying creature' and the abstract 'bird' class implements it, but also bats,flies, wasps and some fish implement this interface. The concept 'interface' is an artifact in Java because it doesn't have multiple inheritance of implementation. In languages such as C++ (that do have MI) there is no need for a separation of classes and interfaces.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-17-2011, 09:32 AM #5
Member
- Join Date
- Nov 2011
- Posts
- 28
- Rep Power
- 0
Re: Abstraction and interfaces
Hmm so this all kind of a way to get around the lack of multiple inheritance in java? And interfaces are just more "broad" or "general" than abstract classes?
- 11-17-2011, 09:40 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Abstraction and interfaces
Sort of; single inheritance makes all defined classes to be a node (or location) in a tree; the root of the tree is the Object class (see your textbook). Sometimes we don't want that and the interface concept helps here: arbitrary classes at arbitrary locations in the inheritance tree can implement a certain interface and can be treated as such, e.g. birds, bats, flees, etc. are nodes in an inheritance tree (at different locations) and implement the 'flying creature' interface. If some code deals with 'flying creatures' it can handle all those birds, bats, flees etc.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Abstraction Assignment Help!
By CoolKidsClub in forum New To JavaReplies: 1Last Post: 04-27-2011, 02:12 AM -
Help with abstraction
By Shephard in forum New To JavaReplies: 5Last Post: 03-05-2011, 09:43 PM -
Are abstraction and encapsulation concepts not in C?
By hitesh_public in forum New To JavaReplies: 1Last Post: 08-20-2010, 02:23 PM -
Abstraction
By maya700 in forum New To JavaReplies: 4Last Post: 07-04-2010, 06:26 PM -
Abstraction
By anurag in forum New To JavaReplies: 6Last Post: 05-15-2010, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks