0

I'm studying patterns and I have a doubt with the Prototype pattern (composition of objects) and memory footprint.

This pattern is a possible solution to the lack of multiple inheritance in Java, but lets suppose for a moment that Java has multiple inheritance.

Is using the implementation of an interface in the Prototype pattern, more efficient than doing multiple inheritance for the memory?

Is doing an "extends" on a subclass, the same in terms of memory footprint as instantiating a new object on that subclass?

lingote
  • 113
  • 1
  • 10

1 Answers1

0

Each Java object has a header, so I would assume that the 'embedded' superclass object consumes less memory than when it is composed within another object (in the first case they share the same object header). Also, in case of composition the parent has a reference (pointer) to the composed object.

So, I would say that "implements" is less efficient, but I can hardly think of a use case in which this would matter in practice.

PS I fail to see how your question is related to the Prototype pattern.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110