# Aliasing vs Delegation

**URL:** <https://www.ruby-forum.com/t/aliasing-vs-delegation/151720>\
**Category:** Ruby\
**Created:** [October 24, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/aliasing-vs-delegation/151720 "2008-10-24T20:04:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 24, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/aliasing-vs-delegation/151720/1 "2008-10-24T20:04:52Z")

</div>

Which would you recommend for the implementation of a stub/mock lib?

Thanks,  
trans.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 25, 2008, 12:01am UTC](https://www.ruby-forum.com/t/aliasing-vs-delegation/151720/2 "2008-10-25T00:01:44Z")

</div>

On Oct 24, 2:04 pm, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Which would you recommend for the implementation of a stub/mock lib?

An update to this question: In considering it most of the day, I’ve  
decided aliasing is a poor approach. The reason is singleton methods.  
Though singleton methods may be rare, their use by the SUT could end  
up clobbering stub methods.

As an alternate to aliasing, singleton methods could be used to define  
stub methods. While they suffer the same potential problem, it is not  
an issue if good practices are used by the SUT, ie. extend objects  
with modules rather than defining singleton methods directly.

So I guess the question has changed. It is now:

Singleton Methods or Delegation?

Related to this, one question I have about best practices of using  
stubs/mocks… Is it considered bad practice to stub/mock an internal  
SUT object? In other words, should stub/mocks always be temporary  
objects that are dropped into the SUT interfaces? (I hope that’s  
clear enough.)

Thanks,  
T.
