![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
what you mean when you talk about a wrapper ... ?
thank you. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
Ok, forget it, I found it, it's a wrapper facade pattern. thank you.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
anybody else have comment ?
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|