Archived

This topic is now archived and is closed to further replies.

Convinience methods in OOP

This topic is 5746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I have a general question about OOP. When programming (OOP), I encounter many situations where you have to make use of some convinient functions (i.e. getTime(), methods to wrap an object several times) that are not provided by the framework/API youre using. I don''t know how I should associate these methods, or actions to my classes or objects. most of my objects can make use of it, so how should I put these together? if I make a class called Convinience, that would be just a collection of convinient functions and not really an object. I hope I made myself clear! Thanks. -Pfhorseti

Share this post


Link to post
Share on other sites
convenience methods (As u put it ) are usually put into the game engine, or sometimes (if you''re using one) into the base level object that the game world objects inherit from (eg. CObject), depending on what the particular method is.

Share this post


Link to post
Share on other sites
This is where I usually just move away from pure OO techniques and use a global function. I mean, these sort of functions don''t really fit in with anything else in a game engine, so why try and force the OO methodology to situations where it doesn''t fit?


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
if you encounter these problems alot, then you might not be making your program as oopy as you might want to.

the problem ofcourse is that your trying to integrate procedural api with oop. what you might want to do is encapsulate various api into objects, and then use those objects through composition or whatever.

how often is getTime used? where at? why?

to make a program OO, is to make the interface OO, resulting in a modular, readible, and extendible system. that means that if the user can program using your objects, using no procedural stuff, then your probably on the right track. that means its ok to have encapsulated api stuff, because the bottom line is that we have to work with third-party/general procedural apis (like win32). if you think about it, interfaces build apon each other. the first interface is ASM, the second is structured apis like C, and then object oriented sytems like C++.
to work in one is to interface with the lower version. (oop->structured procedural->unstructured)

before you go about writting your code, you need to go about thinking about it. design your user inteface , design your objects, design your code, write your code.

when i say user, i mean any user. if your writting a low level object engine, then, you might use a ton of apis and procedural stuff, like directX. the user then will work your objects in a oopy way, with no need to know about your implementation details. his users in turn would write programs in an oopy way too.

Share this post


Link to post
Share on other sites
quote:
Original post by Pfhorseti
Hi!

I have a general question about OOP.
When programming (OOP), I encounter many situations where you have to make use of some convinient functions (i.e. getTime(), methods to wrap an object several times) that are not provided by the framework/API youre using. I don''t know how I should associate these methods, or actions to my classes or objects.
most of my objects can make use of it, so how should I put these together? if I make a class called Convinience, that would be just a collection of convinient functions and not really an object. I hope I made myself clear!

Thanks.

-Pfhorseti


Lookup friend functions & Class in any good C++ OOP Book. Or another way of doing it is to create a base class from which all classes are derived and then use the base class as an argument for your function...




"And that''s the bottom line cause I said so!"

Cyberdrek
cyberdrek@gdnmail.net
Founder Laval Linux

/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

Share this post


Link to post
Share on other sites
quote:
Original post by Void
Note - getTime can actually be encapsulated into a timer class.


That''s usually what I do, but I also give it the added ability to call a specific function at a certain time.


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
Maybe make a class called CEnvironment or something where you wrap all system functions (make them static) and implement the ones that aren''t provided. It will help with portability also.

Share this post


Link to post
Share on other sites