473,495 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Abstract Base Collection

I am attempting to create a base collection that I can use to derive
strongly typed collection. My base collection class will derive from
CollectionBase and I want my typed collections to be forced to
implement certain methods:
public abstract class MyCollectionBase: CollectionBase
{
public void Sort() {.... SORT IMPLEMENTATION }
public void Filter() {...> FILTER IMPLEMENTATION }
}
Sort and Filter can be done generically so I am including those in my
base class design. Now I want to force my derived classes to implement
the strongly typed Add(typedObject object), Remove(), this[int index]
members....

I am not sure how to make the derived classes be forced to implement
the interface...

public abstract int Add(...... DON'T KNOW WHAT TO PUT HERE .....)
{
return List.Add(...);
}

When I define the methods it makes me define the types for the
parameters and then I can't implement a typed Add(), this[] methods in
my derived classes.... Interfaces seem to have the same issue because
I have to define the "types" of the methods, etc..
I hope this all makes sense to somebody...

Thanks,
Josh

Nov 16 '05 #1
5 2083
You probably cannot force a method to be implemented unless you give it the
exact signature, which means that you know what types will be passed. That
might be one reason why CollectionBase does not force the methods to be
implemented (they are implemented as implicit methods). The problem is
that, if I understand you correctly, you do not know what type will be added
to the collection until someone derives a class.

Now, you could always use "object" in the signature, which of course defeats
the purpose of trying to enforce a strongly typed collection.

"aa7im" <jo**@nautilusnet.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am attempting to create a base collection that I can use to derive
strongly typed collection. My base collection class will derive from
CollectionBase and I want my typed collections to be forced to
implement certain methods:
public abstract class MyCollectionBase: CollectionBase
{
public void Sort() {.... SORT IMPLEMENTATION }
public void Filter() {...> FILTER IMPLEMENTATION }
}
Sort and Filter can be done generically so I am including those in my
base class design. Now I want to force my derived classes to implement
the strongly typed Add(typedObject object), Remove(), this[int index]
members....

I am not sure how to make the derived classes be forced to implement
the interface...

public abstract int Add(...... DON'T KNOW WHAT TO PUT HERE .....)
{
return List.Add(...);
}

When I define the methods it makes me define the types for the
parameters and then I can't implement a typed Add(), this[] methods in
my derived classes.... Interfaces seem to have the same issue because
I have to define the "types" of the methods, etc..
I hope this all makes sense to somebody...

Thanks,
Josh

Nov 16 '05 #2
Hi,
Unforturnally what you want is not possible with the actual implementation
(it will be doable with C# 2.0 ).

As you don;t know the exact signature of the method you cannot declare it a
priori.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"aa7im" <jo**@nautilusnet.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am attempting to create a base collection that I can use to derive
strongly typed collection. My base collection class will derive from
CollectionBase and I want my typed collections to be forced to
implement certain methods:
public abstract class MyCollectionBase: CollectionBase
{
public void Sort() {.... SORT IMPLEMENTATION }
public void Filter() {...> FILTER IMPLEMENTATION }
}
Sort and Filter can be done generically so I am including those in my
base class design. Now I want to force my derived classes to implement
the strongly typed Add(typedObject object), Remove(), this[int index]
members....

I am not sure how to make the derived classes be forced to implement
the interface...

public abstract int Add(...... DON'T KNOW WHAT TO PUT HERE .....)
{
return List.Add(...);
}

When I define the methods it makes me define the types for the
parameters and then I can't implement a typed Add(), this[] methods in
my derived classes.... Interfaces seem to have the same issue because
I have to define the "types" of the methods, etc..
I hope this all makes sense to somebody...

Thanks,
Josh

Nov 16 '05 #3
I was hoping that was not the case.... I guess I will hope the
developers will remember to implement all collections the same...
That sucks...

Nov 16 '05 #4
My approach for strongly typed collections is i have a template class,
where i use <T> everywhere to reference the type.
To implement the collection for a type, i copy the template
and replace all occurrences of <T> with the type name.
Done in 30 seconds.
This is really the best solution, since i would not think of using
System.Collections.CollectionBase
and since Generics is not yet present.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"aa7im" <jo**@nautilusnet.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I was hoping that was not the case.... I guess I will hope the
developers will remember to implement all collections the same...
That sucks...

Nov 16 '05 #5
I am currently using CodeSmith to produce my collections using a
template that I wrote. Works great, but seemed like their was a more
OOP way of forcing implementation details for the derived classes....

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6623
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
0
1802
by: XSD-optimist | last post by:
I am trying to generate the classes for an XSD schema using the Microsoft XSD Object Code Generator (XSDObjGen). I am having a schema that contains the definition of the following: 1. a complex...
6
3269
by: Tamir Khason | last post by:
I have some classes that basicly do the same things but different way. There are no default constructors in those classes each constructor should recieve same value So Fooclass:MyBasicClass...
9
7540
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
6
3124
by: Alden Pierre | last post by:
Hello, http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7 As per the link above it's wise to have a virtual deconstructor when creating an abstract class. Here is when I'm...
4
2678
by: Craig | last post by:
Hi Consider the following code snipet: delegate void SomeDelegate(ICollection collection); void SomeDispatch() { ArrayList al = new ArrayList(); al.Add("hello");
0
2662
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
0
2808
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
4
6556
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.