Need Class Collection advice

R

R Avery

I have been thinking of various ways to populate my collection classes
with its children.


1) I could create the .Add function of the collection class to accept a
child object as an argument, which then adds the child to the collection.

2) I could create the .Add function of the collection class to not
accept any arguments, and to just return a new child object


I do not know when one method would be preferred over the other. Can
anyone help? Thanks!
 
C

Chip Pearson

I would definitely go with approach #1, if for no other reason is
than it would make your collection class work more like a regular
collection object. I don't see what advantage there would be to
using approach #2.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
O

onedaywhen

I disagree, I'd go for

3) create the .Add function of the collection class to accept any
arguments required to create a child object and return the new child
object

to make it work more like a regular collection *class*. For example,

Set ws = ThisWorkbook.Worksheets.Add(1)

For me, adding a child object directly to the collection is usually a
Private/Friend method of my object hierarchy i.e. not a Public method
exposed to the client.

--

Chip Pearson said:
I would definitely go with approach #1, if for no other reason is
than it would make your collection class work more like a regular
collection object. I don't see what advantage there would be to
using approach #2.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top