ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Class Collection advice (https://www.excelbanter.com/excel-programming/293995-need-class-collection-advice.html)

R Avery

Need Class Collection advice
 
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!

Chip Pearson

Need Class Collection advice
 
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



"R Avery" wrote in message
...
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!




R Avery

Need Class Collection advice
 
Alright! Just needed advice from a pro. ;D Thanks.

onedaywhen

Need Class Collection advice
 
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" wrote in message ...
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



"R Avery" wrote in message
...
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!


--


All times are GMT +1. The time now is 07:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com