There is no universal "best" options - both approaches have their pluses and minuses.
The first approach lets you extend hierarchy by additional subclassing (e.g. you can define class Diner extends Restaurant
and class FastFoodPlace extends Restaurant
, and pass them to your RestaurantManager
. You can also change the signature of the constructors of your Restaurant
without consequences in the RestaurantManager
's methods.
The second approach lets RestaurantManager
"own" the implementation of Restaurant
from the caller, hiding it from outside view behind some interfaces. Among other things, it lets RestaurantManager
decide if a Restaurant
is to have a key or not, when and how that key is set, and so on.
You pick one or the other approach based on your needs. The first approach offers more flexibility outside the RestaurantManager
, while the second approach offers better encapsulation inside RestaurantManager
. The coupling between the manager and the hierarchy becomes tighter, which makes extending the hierarchy harder.