Solved

OOP Help!

Posted on 2002-04-29
8
293 Views
Last Modified: 2013-12-14
Hi all

I've been programming commercially in VB for about 2 years now, i know C/C++ quite well and im im pretty much there with C# syntax too.

My question is how does OOP fit into my applications?

Everytime i read tutorials on this subject it all makes perfect sense but when you try and put it in to practice it doesn't seem to go as smooth as i'd like.

As an example i have a tblClients table in SQL which basically holds some basic information on our clients..

Would i build a Client Class for this object? Would i make the columns in the the table the field variables of the class?

I can see how all this would work simply by providing methods of the client class but this doesn't seem right???

Thanks in advance
Rob
0
Comment
Question by:Rob_Saville
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 30

Expert Comment

by:Axter
Comment Utility
>>Would i build a Client Class for this object? Would i
>>make the columns in the the table the field variables
>>of the class?
The general answer is Yes and Yes, but it depends on the requirements and methods you need to use.

>>I can see how all this would work simply by providing
>>methods of the client class but this doesn't seem
>>right???
What doesn't work.
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
OOP is more design and organization. It is possible to develop completely without using objects (OOP programming), but when you start to create complex programs, it starts to get very difficult to tell which functions can change which variables, and which functions depend on which other functions.

This is where OOP comes in. It groups all of your variables and functions that affect each other together. Once you have created this object (group of variables and functions), if you change the object - the way it works internally, you should never have to touch any other objects or code.

Since you've programmed in VB for years, have you noticed all the controls you can use? How they all have methods that you can call or properties you can change? Anything you do to a control doesn't affect your calls to other controls. That control is an object, an isolated piece of working code.

You can have 20 controls or more, of the same type, in a single application, and none would even know the others existed, nor would they need to. A control (object) works all by itself. Where it is doesn't really matter. What else is there doesn't really matter. It knows itself, and it interacts with the outside world through its interface - a known set of functions other code can call to interact with this control.

So, OOP programming, in summary, is a bunch of variables and functions that all work together, are isolated from the outside world, can be interacted with through an interface, and changes to the inside of the object won't affect anything else outside of the object in terms of how you call/use the object.

A lot of nitpickers can tear my explanation up, but the general idea is there. It looks like you've read a fair bit into OOP, so hopefully this'll help make it easier to understand what you've been reading. :)
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
This question is current, others below, are not.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20186943.html
http://www.experts-exchange.com/questions/Q.20231214.html
http://www.experts-exchange.com/questions/Q.20261107.html
http://www.experts-exchange.com/questions/Q.20294974.html
http://www.experts-exchange.com/questions/Q.20285166.html
http://www.experts-exchange.com/questions/Q.20287524.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
>> but when you try and put it in
to practice it doesn't seem to go as smooth as i'd like.

It takes time to become smoother and smoother, reading good tutorials is fine but reading good wriiten OOP code for some real-life application is the best source of inspiration and example.

Another thing that can help you become smoother is by studying OO design patterns, most of the times you dont have to invent anything decent on yourself and use design patterns that fit well into your situation. This also gives you the sense of having proper OOD etc. if you follow things intelligently.

>> Would i build a Client Class for this object? Would i make the columns in the the table the field variables
of the class?

This depends upon your situation, maybe you can have a generic table class and field classes and you can create an instance of table class for your tblClients table, the columns of that tables can be represented by a collection of fields class.
What i am saying is to model the Recorset fields pattern that ADO has, and isnt it flexible. but then do you even need a table class ?

OR maybe you can have a specialized class for that table with columns for that table as its data members, would be much more efficient. (you can do this if there arent going to be many tables or different varieties of database access).

But then here is the trade off between genericity and perhaps efficiency, i say you try both approaches and then perhaps you'll be able to appreciate a particular style.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Rob_Saville
Comment Utility
Totally understand what everyone is saying..

Given that i have a clients table and there are certain actions you generally take on each client. ie, add project, rename client, delete client etc..

If were to instantiate a new client object would i go ahead and do something like:

Client myClient = new Client(ClientID) // c#

(by passing in a clientID you have access to each individual client)

What if i wanted to perform an action on every client at the same time?  Would this be another different class?

Just relating all the methods and variables into a class doesn't look very object OO.

I think i might be trying to over complicate things.

Im trying to write more a business tool rather than a component so perhaps thats why im getting confused.
0
 
LVL 22

Accepted Solution

by:
ambience earned 200 total points
Comment Utility
>> Client myClient = new Client(ClientID) // c#
(by passing in a clientID you have access to each individual client)

That is possible, though not the only approach, although this appears intuitive. This would require your client to always be created based upon an ID, what if you are adding new clients


>> What if i wanted to perform an action on every client at the same time?  Would this be another different
class?

Dont really understand what you mean by at the same time, perhaps you mean same action on all clients. for e.g. add a project to all clients, well then you can go ahead iterate over the client list and call add_project on all of them. Or better you can have a class say ClientManager.
There are certain trade offs with both approaches.

You can think of the manager as a container of clients, so for e.g. this class is responsible of adding new clients, and methods which apply to all client can be put into this class, say add_project_to_all_clients kind of methods. But then there comes the problem of updating each client object with changes in database.

Also this would ease the case of Deletes, for e.g. what happens if you call Client.Delete(), would your client object be usable ?

such conditions can be handled easily by using a Manager/Container.

One more thing if this is a database app then perhaps you wont like to be accessing the database for each operation when you can do the operations in bulk,  for all clients if client.update_status() results in accessing the database to update a particular client status, this seems to be an overkill, for you can do that in a single operation.

This topic can go on into depth as much as you want to, but perhaps you can give your feed back about what you think of it and then it would be much easier to continue.

>> Just relating all the methods and variables into a class doesn't look very object OO.

a restatement would be, encapsulating all the related methods and variables into a class (can be) considered as OO.
0
 

Author Comment

by:Rob_Saville
Comment Utility
ambiance

ok i pretty much know where im going from here, i think im definitely trying to complicate this to much.

Im now compitent with c# syntax and classes and OOP i just need to figure out the best design for what im doing

Cheers

0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
Usually the best design is to break things up into real world objects, so it is intuitive. We (humans) think in object oriented terms. So:

You have a client. This client could be anything - but it is still an object that you can relate to. It may have a connection. The client connection is a separate object, and its job is to connect the client to whatever, maybe a database. You have a database. Another separate object.

Just like an object is a Microwave, it cooks food, it has certain properties, like width of the oven, and height of the oven. It also has procedures, like Cook, and Timer. It has output functions (get) like the LED display, and input functions (set) like the number pad. That's all there really is to it about object oriented programming - it is "object" oriented...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now