Jump to content

OOP Question about common method in base class (probably simple)


Recommended Posts

My OOP naivety shows again, but oh well, I'll learn, albeit slowly. I have a "network connection" base class and from it I have some child classes. I want to create a public method to check if a connection is valid. It seems like this is a method that should somehow go in the base class because it will be the same for all classes (check a connection refnum whether it's tcp,udp, etc, and see if it's valid). But, I am not sure how to best accomplish getting the connection refnum which is held in the child class, into the base class. I obviously don't want some sort of public accessor to call to return the refnum to be passed to the base classes method because I don't want the connection refnum available outside the class. But, I was trying to avoid having a "is connection valid" method in every single class also, when it seems a generic method would work fine.

Suggestions?

Edited by for(imstuck)
Link to comment

I'd expect you need to do more then just a simple valid-refnum check to see if a connection is valid and that it would be different actions depending on the protocol that is used. So I would opt for implementing a dynamic dispatch "CheckConnection" method and make it "Must Override" so that each child has to implements it's own.

If you're really certain that you can use the same piece of code to check connection for all child implementations, I vote for AQ's solution above.

Link to comment
It sounds like your refnum is the same type between each of the child classes?
His refnum is explicitly not the same. It's TCP or UDP or whatever.

I should note, regarding my solution, that each child class would have to cast its reference as an int32 in order to return it to parent.

Jeffery raises the point about doing more than just checking for Not A Refnum... i.e., checking if a non-zero refnum is still valid. Very important, for (imstuck): read this please:

http://lavag.org/top...ur-app-at-risk/

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.