Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 24th, 2006, 12:22 PM   #1
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Post New to OO need advice to create the classes

Hi all.

I want to learn C++. I have a very good knowledge of C and I want to learn the OO way to code.

Here I would like to get some advice to know the number of class I should create and what the class should contain. Here is my project I'd like to build (it will work on linux):

I want to listen to the network (socket). When I receive a call, I want to put it in a queue. The first person on the queue can send commands to a device connected to a serial port for 1 min.

Where I listen the socket ? In the main ? In a class ?

I wait for your advice.

Thank you.
weeb0 is offline   Reply With Quote
Old Jan 24th, 2006, 1:08 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3 Polyphemus_ is on a distinguished road
I personally prefer to write a wrapper around the socket, and also one for the server socket (to accept connections). Then it's also handy to create a class to write to the serial port, and I guess that's it.
Polyphemus_ is offline   Reply With Quote
Old Jan 24th, 2006, 1:11 PM   #3
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
what you mean when you talk about a wrapper ... ?

thank you.
weeb0 is offline   Reply With Quote
Old Jan 24th, 2006, 1:23 PM   #4
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Ok, forget it, I found it, it's a wrapper facade pattern. thank you.
weeb0 is offline   Reply With Quote
Old Jan 24th, 2006, 1:23 PM   #5
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
anybody else have comment ?
weeb0 is offline   Reply With Quote
Old Jan 24th, 2006, 1:27 PM   #6
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
A wrapper is just what the word says. You know burritos? Well they are wrappers around some meat, beans and more. In programming, a wrapper also means a layer, this is used to make it simpeler for the next time/person. The wrapper often wraps around some protocol, in this case it's around sockets.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jan 24th, 2006, 1:29 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Yeah. If you don't have a basic idea of the utility of OO, you might want to read the short blurb referenced in my signature. Read the pronunciamentos of all of us carefully and with all the discernment you can muster. There's a lot of BS produced by many of us.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 24th, 2006, 2:15 PM   #8
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
I understand the basic idea behind the OO. But, what I don't understand well, is how I can wrap the socket in my project.

For the serial connections, it's fairly easy since I don't receive any information from the serial port, so I don't need any callback or anything like this.

but for the serial, I must wait for a connection. Ok, I can use the class_socket::accept(). The function will return the socket.

But, how I can know a client has sended me information ? I have to build a callback ? I have to poll ? This is what I don't understand. In my C project, I use the select(....) in an infinite loop to know when I receive some information ... but, using a class, I have to gain experience to understand well that... Anyone can help me ? thank you.
weeb0 is offline   Reply With Quote
Old Jan 24th, 2006, 2:59 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
If you're satisfied with an infinite loop, you can accomplish the same thing inside a class method as you do in a normal function, or inline. I don't see precisely what you're not seeing, so to speak. Piddle with some objects to get the feel of the paradigm, then give your project some good think time, then write some pseudocode (or perhaps even some actual code) and post back for comments or for help with problems. Never jump onto the keyboard without investing in thought and design; it'll give you ulcers and put you in the unemployment line. You can ask for conceptual help as well as coding help.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 24th, 2006, 3:58 PM   #10
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Thank you DaWei. In the conceptual area, which tool are you using to draw uml ?

thank you for your comment.

I'll try visualise how I can build the classes. If something I don't understand, I'll ask in this thread ;-) THanx a lot.
weeb0 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC