Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner design question regarding simple P2P program.

 
Tarek Khojah
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tarek Khojah
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic