Creating my own Business Object

Creating my own Business Object

Old forum URL: forums.lhotka.net/forums/t/1823.aspx


Blarm posted on Thursday, November 23, 2006

I have searched through the posts but can't find a complete of the sytax (VB.Net) for creating my own Business Objects. I have pieced this together from several posts, but can't find EditableRootListBase.  So far I have the other six classes:

<Serializable()> _
Public MustInherit Class IBOBusinessBase(Of T As IBOBusinessBase(Of T))
Inherits Csla.BusinessBase(Of T)
End Class

<Serializable()> _
Public MustInherit Class IBOBusinessListBase(Of T As IBOBusinessListBase(Of T, C), C As Csla.Core.IEditableBusinessObject)
Inherits Csla.BusinessListBase(Of T, C)
End Class

<Serializable()> _
Public MustInherit Class IBOCommandBase
Inherits Csla.CommandBase
End Class

<Serializable()> _
Public MustInherit Class IBONameValueListBase(Of K, V)
Inherits Csla.NameValueListBase(Of K, V)
End Class

<Serializable()> _
Public MustInherit Class IBOReadOnlyBase(Of T As IBOReadOnlyBase(Of T))
Inherits Csla.ReadOnlyBase(Of T)
End Class

<Serializable()> _
Public MustInherit Class IBOReadOnlyListBase(Of T As IBOReadOnlyListBase(Of T, C), C)
Inherits Csla.ReadOnlyListBase(Of T, C)
End Class

Do these look correct and can someone let me have the code for EditableRootListBase.

Thanks,

Bill

 

JoeFallon1 replied on Thursday, November 23, 2006

Bill,

They look fine! Nice work consolidating them for everyone.

Comments:
1. I hope your company name is IBO otherwise I have a minor issue with your naming convention. Even if it is IBO I would reconsider the prefix for your custom classes. The problem is that Interfaces always begin with a capital I. So your names are just confusing the types.

2. I have not implemented EditableRootListBase so I don't have the code. But you got this far - why don't you post it for the rest of us? <g>

3. For ReadOnlyListBase you can consider adding a constraint to C like you did in BusinessListBase.
Something like:  C As Core.IReadOnlyObject

Joe

 

 

Blarm replied on Thursday, November 23, 2006

Slight change as suggested by Joe:

<Serializable()> _
Public MustInherit Class MyBOReadOnlyListBase(Of T As MyBOReadOnlyListBase(Of T, c), C As Csla.Core.IReadOnlyObject)
    Inherits Csla.ReadOnlyListBase(Of T, c)
End Class

[Serializable()]
public abstract class MyBOReadOnlyListBase<T, C> : Csla.ReadOnlyListBase<T, c> where T : MyBOReadOnlyListBase<T, c> where C : Csla.Core.IReadOnlyObject
{
}

Once I get the EditeableRootListBase then maybe I will ask Rocky if he could add them to an FAQ or something to save other people time.

 

Bayu replied on Thursday, November 23, 2006

Nice work!

Maybe prefix them with BBO (Bill's Business Objects) in ordet to ensure your legacy. Stick out tongue [:P]

Bayu

Blarm replied on Thursday, November 23, 2006

Yes that was rather stupid of me the prefix with I. My company is called Inventive and I just went for IBO - Inventive Business Objects without thinking.

Anyway here's the C# version, but I haven't got the EditableRootListBase for that either.

[Serializable()]
public abstract class MyBOBusinessBase<T> : Csla.BusinessBase<T> where T : MyBOBusinessBase<T>
{
}

[Serializable()]
public abstract class MyBOBusinessListBase<T, C> : Csla.BusinessListBase<T, C> where T : MyBOBusinessListBase<T, C> where C : Csla.Core.IEditableBusinessObject
{
}

[Serializable()]
public abstract class MyBOCommandBase : Csla.CommandBase
{
}

[Serializable()]
public abstract class MyBONameValueListBase<K, V> : Csla.NameValueListBase<K, V>
{
}

[Serializable()]
public abstract class MyBOReadOnlyBase<T> : Csla.ReadOnlyBase<T> where T : MyBOReadOnlyBase<T>
{
}

[Serializable()]
public abstract class MyBOReadOnlyListBase<T, C> : Csla.ReadOnlyListBase<T, C> where T : MyBOReadOnlyListBase<T, C>
{
}

 

Sarosh replied on Friday, November 24, 2006

Hi!

This is what I use for EditableRootListBase

[Serializable()]
public abstract class MyBOEditableRootListBase<T> : Csla.EditableRootListBase<T>  where T : Csla.Core.IEditableBusinessObject, Csla.Core.ISavable
{
}

 

Sarosh

Blarm replied on Monday, November 27, 2006

Thanks Sarosh.

I am going to create a new post with the VB.Net and C# code for all the classes.

JonM replied on Monday, November 27, 2006

There are templates included with the CSLA framework that work pretty well.  Also, http://onelittlevictory.com has a lot of example code.

rasupit replied on Friday, April 06, 2007

I use the special purpose generics delegates (Action, Predicate, Converter) a lot of on my read only list object therefore I added a few convinience methods on my inherited ReadOnlyListBase.

I know Rocky had this in Feature Wish List (item 5) at http://lhotka.net/Article.aspx?area=4&id=42066ed8-ea65-44a3-b7fd-035c9d8bfa36, but until is implemented, here's the code that I added that I think others might also find it usefull:

public List<TOutput> ConvertAll<TOutput>(Converter<C, TOutput> converter)

{

if (converter == null) throw new ArgumentNullException("converter");

List<TOutput> list = new List<TOutput>(this.Count);

for (int i = 0; i < this.Count; i++)

{

list.Add(converter(thisIdea [I]));

}

return list;

}

public List<C> FindAll(Predicate<C> match)

{

if (match == null) throw new ArgumentNullException("match");

List<C> list = new List<C>();

for (int i = 0; i < this.Count; i++)

{

if (match(thisIdea [I]))

{

list.Add(thisIdea [I]);

}

}

return list;

}

public C Find(Predicate<C> match)

{

int idx = FindIndex(0, this.Count, match);

if (idx == -1) return default(C);

return this[idx];

}

public int FindIndex(int startIndex, int count, Predicate<C> match)

{

if (match == null) throw new ArgumentNullException("match");

if (startIndex > this.Count) throw new ArgumentOutOfRangeException("startIndex");

if (count < 0 || (startIndex + count) > this.Count) throw new ArgumentOutOfRangeException("count");

int endIndex = startIndex + count;

for (int i = startIndex; i < endIndex; i++)

{

if (match(thisIdea [I]))

{

return i;

}

}

return -1;

}

public int FindIndex(int startIndex, Predicate<C> match)

{

return FindIndex(startIndex, this.Count - startIndex, match);

}

public int FindIndex(Predicate<C> match)

{

return FindIndex(0, this.Count, match);

}

Smile [:)]

Copyright (c) Marimer LLC