I am also curious about how to hide that Add(item As T) method from the public view...preferrably I would like to do it in my base class where I hide other things too.
<Serializable()> _
Public MustInherit Class JTBusinessListBase(Of T As JTBusinessListBase(Of T, C), C As Csla.Core.IEditableBusinessObject) Inherits BusinessListBase(Of T, C)One other thing I do is to Shadow the AllowEdit property to be ReadOnly...and added a protected sub SetAllowEdit. It gets rid of all the public stuff that our users would get confused with anyway.
CSLA pattern is so nice in that I only expose the bare minimum at the public level.
I have tried several ways to hide Add() in the base class but I can't figure it out. Would I have to do something in each collection class?
I don’t recommend this, but…
You can always shadow Add as a private member. In VB this is
done with the Shadows keyword, and in C# with the new keyword.
It is a bad idea, because it breaks polymorphism (you are
literally removing a method that should be exposed via the base class),
but it does work.
Private Shadows Sub Add(item As T)
End Sub
Rocky
From: swegele
[mailto:cslanet@lhotka.net]
Sent: Monday, December 10, 2007 9:38 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] There is allways a Public Add method in
BusinessListBase?
I am also curious about how to hide that Add(item As T) method from the
public view...preferrably I would like to do it in my base class where I hide
other things too.
<Serializable()> _
Public MustInherit Class JTBusinessListBase(Of
T As JTBusinessListBase(Of T, C), C As
Csla.Core.IEditableBusinessObject)
Inherits BusinessListBase(Of
T, C)
One other thing I do is to Shadow the
AllowEdit property to be ReadOnly...and added a protected sub SetAllowEdit.
It gets rid of all the public stuff that our users would get confused with
anyway.
CSLA pattern is so nice in that I only expose the bare minimum at the public
level.
I have tried several ways to hide Add() in the base class but I can't figure
it out. Would I have to do something in each collection class?
Shadowing is limited, and works in an almost opposite way from
virtual methods.
Shadowing works based on the type of the VARIABLE you are using,
not the type of the OBJECT you are using.
In other words, shadowing only works if the variable is the same
as the type of the class that does the shadowing.
Dim x As CustomerList
x.Add(…)
Add() will be unavailable only if CustomerList is the type that
shadowed the method.
But shadowing is the only option I’m aware of for this
issue.
Rocky
From: swegele
[mailto:cslanet@lhotka.net]
Sent: Monday, December 10, 2007 9:57 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: There is allways a Public Add method in
BusinessListBase?
Tried
your method and it doesn't work if I do it on the base class...only if I do it
on the actual business list class itself. It still shows up publically as
an overload of Add(item as T).
It
is strange on 2 accounts:
1.
Because literraly item As T is showing up to the user...I would think
intellisense would show the correct type instead of T
2.
Still shows up publically even though I shadow it in the base class as private
or friend
OK that makes sense why it only works when I shadow it on the class and not just the base class.
But if I don't do anything...(meaning no shadowing or funky stuff)...why does the method Add(item As T) show up to a consumer of my business objects?
I would think it would show the actual type like Add(item as Customer) or whatever?
Thanks ajj3085,
2nd issue is I don't understand why intellisense would show a "T" instead of the actual type. If I use generics to make a list of type Customer, isn't the Add supposed to look like this in intellisense Add(item as Customer). Mine doesn't. Mine looks like this Add(item as T).
Is this because I have my own base class JTBusinessListBase that inherits from Rocky's? Any body else seen this problem?
The base class that inherits from Rocky's is
<Serializable()> _
Public MustInherit Class JTBusinessListBase(Of T As JTBusinessListBase(Of T, C), C As Csla.Core.IEditableBusinessObject) Inherits BusinessListBase(Of T, C)
The actual class (akin to customer) that I use is this
<Serializable()> _
Public
Class JTCaseRequestList Inherits JTBaseObjects.JTBusinessListBase(Of JTCaseRequestList, JTCaseRequest)I needed to bring this topic/thread back up because of something i am noticing here with my Developers.
a lot of places they are using the Add/Insert/Remove methods... instead of AddItem/InsertItem/RemoveItem.
I want to physically hide the first set of options so it does not even come up in the list of methods? I want to do this so the Devs here will be forced to use AddItem, etc. I saw the previous posts on encapsulation... but does anyong have a better idea to hide these methods?
Also, what are the consequences with using the <Obsolete> Attribute instead? Is there some overhead with this attribute?
ward0093
There is no overhead, it is only used by compiler, not run time.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ward0093
[mailto:cslanet@lhotka.net]
Sent: Saturday, November 22, 2008 11:35 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: There is allways a Public Add method in
BusinessListBase?
I needed to bring this topic/thread back up because of something i am
noticing here with my Developers.
a lot of places they are using the Add/Insert/Remove methods... instead of
AddItem/InsertItem/RemoveItem.
I want to physically hide the first set of options so it does not even come
up in the list of methods? I want to do this so the Devs here will be
forced to use AddItem, etc. I saw the previous posts on encapsulation...
but does anyong have a better idea to hide these methods?
Also, what are the consequences with using the <Obsolete> Attribute
instead? Is there some overhead with this attribute?
ward0093
Copyright (c) Marimer LLC