aspose file tools*
The moose likes Beginning Java and the fly likes Beginner design question regarding simple P2P program. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beginner design question regarding simple P2P program." Watch "Beginner design question regarding simple P2P program." New topic
Author

Beginner design question regarding simple P2P program.

Tarek Khojah
Ranch Hand

Joined: Jul 21, 2007
Posts: 58
Ok, I have this class the should capture and send audio, I have a "capture" and "send" button, let's call this class "AudioCapture".

Where should I include all the networking stuff? At first, I thought I should make another class (Let's call it "Program") that sets up the networking then make an AudioCapture object each.



But then I thought, when I click the "send" button, and send() is called from the audio object, how will I be able to include the new parameters (streams and/or sockets) that will enable my send() method to work as it should?

I guess I could set up the networking and do all the capturing/sending in one class, but would that be the correct approach?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's good to have a class do only one thing, or as Robert Martin puts it, to have only one reason to change. If a class did capture and send it might change because the capture source changes or because the network stuff changes, so that's a hint to make two things.

It's also good to tell objects to do things for you rather than ask them for data. Maybe you'd have something like:

All the capture logic is in the Capturer. All the storage is in AudioClip.
Maybe someStream could go to an audio player or a network connection to a peer. Does that give you any ideas?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tarek Khojah
Ranch Hand

Joined: Jul 21, 2007
Posts: 58
Well, doesn't it make sense to have the capture and the send methods in the same class? After all, the "audio" class launches a form with buttons on it, including "send" and "capture", are you still suggesting I put my send() method in another class?

Also, when I asked my original question, I totally forgot that I can use instance variables, don't ask me why O_o
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beginner design question regarding simple P2P program.
 
Similar Threads
SimpleGui1B exception errors
problem with program
Object Creation
Applet not working
Simple question! I keep getting NullPointerException error!