thanks, Robert, Ryan and Darry, I agree it's a design problem.

I know if I choose to include an object SshCon in LinuxSshCon, not inheritance.
Then I won't have any of these problems.

I'll look into some OO books, to get a better design next time. :)

On Fri, Oct 21, 2011 at 4:40 AM, Darryl L. Pierce <mcpierce / gmail.com> wrote:
> On 10/19/2011 09:16 AM, salamond wrote:
>> Hi, all.
>>
>> I'm creating an automation framework, and met this inheritance
>> private/protected problem.
>> Say I'm having SshCon and LinuxSshCon
>> class SshCon
>> def connect
>>  ¨Âí䨩
>> end
>> def cmd
>>  ¨Âîä
>> def search
>>  ¨Âí䨢¢©
>> end
>> end
>>
>> class LinuxSshCon < SshCon
>> def cmd
>> format()
>> super()
>>  ¨Âîä
>> end
>>
>> lsc = LinuxSshCon.new
>> lsc.connect # here it would use the cmd in LinuxSshCon, and cause me
>> some trouble
>> lsc.cmd
>
> I agree with another poster on this thread: the above has serious code
> stink. Why does LinuxSshCon override cmd() if that is a problem for the
> parent class? It seems that what cmd() is doing in your LinuxSshCon
> class needs to be split up into one or more additional methods.
>
>> My problem is this:
>> When I overwrite a method in sub class, is there a way I can keep the
>> original class calling its own method?
>> I tried
>> def connect
>>  ¨Âåìæ®ãí>> end
>> or use private/protected to claim cmd, none of them works
>
> Go back and revisit your design. If the method ON the base class should
> only invoke the base class method then your child shouldn't be
> overriding it.
>
> --
> Darryl L. Pierce <mcpierce / gmail.com>
> http://mcpierce.multiply.com/
> "What do you care what people think, Mr. Feynman?"
>
>