OO style question......

joeq

Board Regular
Joined
May 31, 2003
Messages
109
Hi All,

Can I get an opinion on something that must be pretty common, but that I've never heard a name for..........

This is the best analogy I can give so here goes...... ;)

Say you have a YARD object. It contains 5 German Shepards objects - the only kind it will ever contain.

However, the YARD object will leash the 1st shepard right near its gate. The other 4 will be leashed further back. For these 4, YARD will wrap and provide to its users: YardDogBark() and YardDogHowl().

The first dog, however, will be wrapped to include YardDogBite(), since it is right near the gate.

I know in terms of inheritance, a derived class is never supposed to "diminish" the ability of the base class, only augment or supplement it.

But YARD contains the dogs. So is it a common / acceptable thing for a wrapping class to wrap MORE of 1 multiply contained object than it does of the others?, thereby making one of the multiple objects somehow different than the others?

Not sure if this breaks any hiding rules like it would for inheriting.

thanks, joe
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Joe

Firstly, I have only ever programmed in VBA so what I say in no way has the backing of any competent OO programmer.

The Yard 'has a' relationship with the Dog objects. The Dog objects are identical (for instance, the Dog by the gate could be replaced by another dog, and the new dog would therefore need the Bite method) so I suggest that all the Dog objects have the bite method.

The way I suggest that the Dog object determines whether or not it can use the bite method is by asking the Yard object first (so when you set a relationship between Yard and Dog, the Yard object retains a property specifiying whether that Dog object has the bite method). Based on the response from the yard object the Dog object can then execute the bite method.

I think it should be this way round and not the Dog object remembering (by wayof property) if it can bite because it is the position of the dog within the Yard object that determines if it can use the Bite method (ie it is the Yard object that determines whether or not they Bite).

As I said, I am no OO programmer, so I may be totally wrong...

:)
 
Upvote 0
Richard, yes thats what I think as well.
Assuming all dogs have the bite, howl, bark, etc functions in them.
And YARD determines which will bite by its placement of the data members.

This idea of "changing" exisiting classes via wrappers does seems to make sense, but I've broken rules before in the name of common sense ;) thx.

The data memebers of Class YARD are:
-------------------------------------
Dim gate_dog_ as new Dog
Dim back_dogs_(4) as new Dog

YARD will wrap the dog functions this way:
----------------------------------------
Public Function GateDogBite() As Boolean
GateDogBite() = gate_dog_.Bite()
End Function

Public Function YardDog1Bite() As Boolean
YardDog1Bite() = back_dogs_(1).Bite()
End Function

etc.......
 
Upvote 0
I apologize! please disregard my last post.

HERE is how the YARD class looks. And this is my application delemma. I'm not dealing with yards and dogs, but the app I am writing is easiest explained that way:

I do want all dogs in the yard to bite, but I want the gate dog to make the others to bite because HE has bitten. I don't want the user of YARD class telling the back dogs to bite - the user will only tell the gate dog. He will bite and then tell the others to.

The data memebers of Class YARD are:
-------------------------------------
Dim gate_dog_ as new Dog
Dim back_dogs_(4) as new Dog

YARD will wrap the dog functions this way:
----------------------------------------
Public Function GateDogBite() As Boolean

GateDogBite() = gate_dog_.Bite()

For i = 1 to 4
back_dogs_(i).Bite()
Next

End Function
 
Upvote 0
This is one of those questions where the answers are on the cusp of my knowledge base. Like Richard, my pedigree is in VBA and I'm a 100% boot-strapper - the formal training I had in programming was so long ago that it's only the principles that remain. OO programming and GUI interfaces did not even exist at the time of my last programming class. So there is a certain risk that I'll embarass myself - but what's life without a little chance now and again? :p

If I were looking at your situation I would be taking a good hard look at the Implements statement and interfaces. I *think* you'd want to create a generic clsDog class and have both the clsGateDog and clsBackDog implement the base class and extend off that.

I would also take a look at custom events and RAISING them. I'm thinking that might be what you need to handle the BITE thing. :unsure:

Again, until recently I could not even have offered these hints [or at least I *hope* they're hints] as I am still tinkering around with these concepts at home in the evenings trying to get comfortable with them.

I hope that, in some way, helps. OK - back to Martin, Puls & Hennig for me. But thanks, Joe, for the excuse to take a break. :LOL:
____________________________________

Hiya, Richard.
 
Upvote 0
Fiddlesticks - I meant to add this and forgot: I would probably use a collection for the child objects instead of an array. But if you are, indeed going to use an array, then don't hard code the loop parameters. Use LBound() & UBound().
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,602
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top