• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object creation using Interface, class and method.  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy partners, hope you can help - I'm trying to understand the below line. It appears by looking at java.sound.midi.* - we are creating an object Interface instance, with a class and a method from another part of the package.

Here it is -



How do we instantiate an object from an Interface, and how does the above all relate. Thank you for your help!
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sands wrote:How do we instantiate an object from an Interface, and how does the above all relate. Thank you for your help!

I suggest you look at this Thread, because it asks almost the same question. If you still have doubts, come back.

Winston
 
James Sands
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, not quite. I think it's to do with implementation from another class but I'm being slow to the punch.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James. Welcome to the Ranch!

Winston's right - it's exactly the same as in that other thread. The MidiSystem.getsequencer() method returns an instance of an unknown class that implements the Sequencer interface.
 
James Sands
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I wanted to be curious, could I find this class you mention? Thanks so far....
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write

But remember, curiosity killed the cat. The point of programming to interfaces instead of concrete implementations is so that you don't have to care about the class; you just care about the behavior that it gives you.
 
James Sands
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stay with me - Junilu you're right - I see I have opened a Pandora's box when I ran that code!!

Ok - I'm looking at this in a real world layman situation - I want to get into music, so I buy a sequencer and I want it to play/process Midi Files. However - One day I get curious HOW my sequencer plays Midi Files so I decide to take my Sequencer apart. I then can't put it back together, and the cat is dead.

As long as I know I CAN do it, I dont need to KNOW.

What do you think? (You're gonna love me!)
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sands wrote:What do you think? (You're gonna love me!)

Hey, y'all have done an awesome job with the Olympics over there and you're right on track with this one but Love is strong word and not one I like to just wave around like that. Let's just say I'm truly impressed.
 
James Sands
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've got the basic concept then?!?

p.s The Olympics are AMAZING! - I don't want them to end!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sands wrote:As long as I know I CAN do it, I dont need to KNOW.

One of the classic examples you'll see is that of driving a car.

In order to drive a car, do you need to know:
1. How the internal combustion engine works?
2. The type of brakes your car has?
3. Hydraulics?
4. Electronics?

Obviously, the answer to all the above is 'no'; and furthermore, if you were thinking about them, it might impair your ability to drive because we puny humans can't deal with too much information at a time.

Same is true of software: If you have a Map of objects, do you care whether it's a HashMap, a TreeMap or a ConcurrentSkipListMap? No. Do you care whether a TreeMap is a red-black tree, an AVL tree, or a splay tree? No.

It's all about managing what a user needs to know to use something; and in general that means: the more you can hide, the better.

Winston
 
Ranch Hand
Posts: 56
Android MyEclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can create object for interface but that should be ref with inherited class.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sands wrote:So I've got the basic concept then?!?

Looks like it to me; that's the "one" I was referring to with "you're right on track with this one"

p.s The Olympics are AMAZING! - I don't want them to end!

Unfortunately, as with all good things, they must. Otherwise, I couldn't get any work done!
 
James Sands
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well - I'm definately coming back - even Arunkumar's short but very sweet comment regarding inheritance prompted me to click on Tree in the Java API and it all made sense. Thank you for sticking with me, you've been a great help!

Greenhotrn Jim.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sands wrote:Thank you for sticking with me, you've been a great help!

You're welcome.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!