Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > conditional object assignment

Reply
Thread Tools

conditional object assignment

 
 
ThatsIT.net.au
Guest
Posts: n/a
 
      08-19-2009
I have an application where different types of users login. depending what
role they are in they are assigned a diffrent user object, admin dataEntry
and so on.

I can do this using some if statments and then makiung a instance of the
corect object. the propble with this is that i have to do this on every
page. what i would like to do is load the same commonUserObject for each
user, and in the class then assign the right object as a child object. i
could then access the object like this


dim oUser as commonUserObject = new commonUserObject
oUser.childObject.someMethod

This will do, but i was wondering if there was a more elegent way of doing
this, can i some how make the commonUserObject morph into the right object.


 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      08-19-2009
On 19 Aug, 14:34, "ThatsIT.net.au" <me@work> wrote:
> I have an application where different types of users login. depending what
> role they are in they are assigned a diffrent user object, admin dataEntry
> and so on.
>
> I can do this using some if statments and then makiung a instance of the
> corect object. the propble with this is that i have to do this on every
> page. what i would like to do is load the same commonUserObject for each
> user, and in the class then assign the right object as a child object. i
> could then access the object like this
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.childObject.someMethod
>
> This will do, but i was wondering if there was a more elegent way of doing
> this, can i some how make the commonUserObject morph into the right object.


Sounds like a case for creating a class and adding it to the App_Code
folder. The constructor could take the user role as a parameter and
configure itself accordingly. That way you can re-use it throughout
the whole site. Maintenance will be far easier because all the code
for setting it up wil be contained in one place.
 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      08-19-2009
"ThatsIT.net.au" <me@work> wrote in
news:98DCE730-D482-4752-9C99-:

> I have an application where different types of users login. depending
> what role they are in they are assigned a diffrent user object, admin
> dataEntry and so on.
>
> I can do this using some if statments and then makiung a instance of
> the corect object. the propble with this is that i have to do this on
> every page. what i would like to do is load the same commonUserObject
> for each user, and in the class then assign the right object as a
> child object. i could then access the object like this
>
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.childObject.someMethod
>
> This will do, but i was wondering if there was a more elegent way of
> doing this, can i some how make the commonUserObject morph into the
> right object.



Set up an object with the common fields. You can load this into session
if you want to avoid going to the database all the time. For the more
specific objects, have them adorn the main user object. If you want, you
can lazy load the other object. This is where you are aiming for,
essentially.

Another method of doing this is to "subclass" the user object into more
specific objects with additional features. On pages you only need the
common bits, simply use it as a user object. On more specific pages,
GetType() and then cast as the other type of object and use the extra
bits.

If you are talking configuration bits (an employee has an SSN, but other
users do not), you can use the built in Profile bits and simply not
assign the extra items for other users. This is very flexible, but note
that the out of the box profile is a bit problematic if you get too
creative (and cleaning up a fubar is a pain). I use custom profile
providers for this reason.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
ThatsIT.net.au
Guest
Posts: n/a
 
      08-20-2009

"Stan" <> wrote in message
news:7d8bbee8-8fa3-4181-8d95-...
> On 19 Aug, 14:34, "ThatsIT.net.au" <me@work> wrote:
>> I have an application where different types of users login. depending
>> what
>> role they are in they are assigned a diffrent user object, admin
>> dataEntry
>> and so on.
>>
>> I can do this using some if statments and then makiung a instance of the
>> corect object. the propble with this is that i have to do this on every
>> page. what i would like to do is load the same commonUserObject for each
>> user, and in the class then assign the right object as a child object. i
>> could then access the object like this
>>
>> dim oUser as commonUserObject = new commonUserObject
>> oUser.childObject.someMethod
>>
>> This will do, but i was wondering if there was a more elegent way of
>> doing
>> this, can i some how make the commonUserObject morph into the right
>> object.

>
> Sounds like a case for creating a class and adding it to the App_Code
> folder. The constructor could take the user role as a parameter and
> configure itself accordingly. That way you can re-use it throughout
> the whole site. Maintenance will be far easier because all the code
> for setting it up wil be contained in one place.


I think want you are sujesting is much what i have done so far, but I cant
do this in the app_code foldee as the app will have many front ends built by
whoever, what i want to do is handle all this in a lower layer.

 
Reply With Quote
 
ThatsIT.net.au
Guest
Posts: n/a
 
      08-20-2009

"Gregory A. Beamer" <> wrote in message
news:Xns9C6C6C5103BF3gbworld@207.46.248.16...
> "ThatsIT.net.au" <me@work> wrote in
> news:98DCE730-D482-4752-9C99-:
>
>> I have an application where different types of users login. depending
>> what role they are in they are assigned a diffrent user object, admin
>> dataEntry and so on.
>>
>> I can do this using some if statments and then makiung a instance of
>> the corect object. the propble with this is that i have to do this on
>> every page. what i would like to do is load the same commonUserObject
>> for each user, and in the class then assign the right object as a
>> child object. i could then access the object like this
>>
>>
>> dim oUser as commonUserObject = new commonUserObject
>> oUser.childObject.someMethod
>>
>> This will do, but i was wondering if there was a more elegent way of
>> doing this, can i some how make the commonUserObject morph into the
>> right object.

>
>
> Set up an object with the common fields. You can load this into session
> if you want to avoid going to the database all the time. For the more
> specific objects, have them adorn the main user object. If you want, you
> can lazy load the other object. This is where you are aiming for,
> essentially.
>
> Another method of doing this is to "subclass" the user object into more
> specific objects with additional features. On pages you only need the
> common bits, simply use it as a user object. On more specific pages,
> GetType() and then cast as the other type of object and use the extra
> bits.
>
> If you are talking configuration bits (an employee has an SSN, but other
> users do not), you can use the built in Profile bits and simply not
> assign the extra items for other users. This is very flexible, but note
> that the out of the box profile is a bit problematic if you get too
> creative (and cleaning up a fubar is a pain). I use custom profile
> providers for this reason.
>
> Peace and Grace,
>



I really dont want to do any casting or detection, well not in more than one
spot that is.
The site will have many front ends, so all the security and validation and
such will be done on a middle layer. In between my business object layer and
the front ends I have waht I am calling the user layer. here i have
different user classes derived from a abstract class. that contatin all the
methods allowed to that user. all common methods and properties are
inhertied from the abstract class. i have done things this way becuse as
long as the user has the right user object I need not worry about
authorization as he is allowed to do or access anything in his class. The
front end will only open one object the correct user object, then in return
the user object will access the bisiness object layer as if it were the
front end.

how i am doing it is fine, but I just thought it would be a little better if
i did not have to use the common.child syntax as it may be a little
confusing for the front end developers.
what i would like is to use a simple

dim oUser as commonUserObject = new commonUserObject
oUser.someMethod

rather then

dim oUser as commonUserObject = new commonUserObject
oUser.childObject.someMethod

But i can live with it

Thanks




> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> | Think outside the box! |
> *******************************************


 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      08-20-2009
"ThatsIT.net.au" <me@work> wrote in
news:975264A2-F00F-4298-8B00-:


> how i am doing it is fine, but I just thought it would be a little
> better if i did not have to use the common.child syntax as it may be a
> little confusing for the front end developers.
> what i would like is to use a simple
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.someMethod
>
> rather then
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.childObject.someMethod


I am rolling off the top of my head, so there is no filter here.

Reflection - a bit too heavy probably
Extension methods - fine, but have to handle when a method does not
exist for an object type

You might even try a combination of both, but while that will work, it
makes things more complex than the child object, so ouch on that.

The child object is certainly the safest, as a person trying a method on
a child object that is incorrect will not compile.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
ThatsIT.net.au
Guest
Posts: n/a
 
      08-21-2009

"Gregory A. Beamer" <> wrote in message
news:Xns9C6D82B2C89D2gbworld@207.46.248.16...
> "ThatsIT.net.au" <me@work> wrote in
> news:975264A2-F00F-4298-8B00-:
>
>
>> how i am doing it is fine, but I just thought it would be a little
>> better if i did not have to use the common.child syntax as it may be a
>> little confusing for the front end developers.
>> what i would like is to use a simple
>>
>> dim oUser as commonUserObject = new commonUserObject
>> oUser.someMethod
>>
>> rather then
>>
>> dim oUser as commonUserObject = new commonUserObject
>> oUser.childObject.someMethod

>
> I am rolling off the top of my head, so there is no filter here.
>
> Reflection - a bit too heavy probably
> Extension methods - fine, but have to handle when a method does not
> exist for an object type
>
> You might even try a combination of both, but while that will work, it
> makes things more complex than the child object, so ouch on that.
>
> The child object is certainly the safest, as a person trying a method on
> a child object that is incorrect will not compile.
>
> Peace and Grace,
>




yes it seems to be the best answer




> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> | Think outside the box! |
> *******************************************


 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      08-21-2009
ThatsIT.net.au wrote:
> I have an application where different types of users login. depending
> what role they are in they are assigned a diffrent user object, admin
> dataEntry and so on.
>
> I can do this using some if statments and then makiung a instance of the
> corect object. the propble with this is that i have to do this on every
> page. what i would like to do is load the same commonUserObject for each
> user, and in the class then assign the right object as a child object. i
> could then access the object like this
>
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.childObject.someMethod
>
> This will do, but i was wondering if there was a more elegent way of
> doing this, can i some how make the commonUserObject morph into the
> right object.
>


You can make the specific user objects inherit your common user object,
and use a factory method to create them:

Dim user As CommonUserObject = CommonUserObject.Create()
user.SomeMethod()

The static Create method will create a specific user object depending on
the conditions, but it's return type is still CommonUserObject.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
ThatsIT.net.au
Guest
Posts: n/a
 
      08-21-2009

"Göran Andersson" <> wrote in message
news:...
> ThatsIT.net.au wrote:
>> I have an application where different types of users login. depending
>> what role they are in they are assigned a diffrent user object, admin
>> dataEntry and so on.
>>
>> I can do this using some if statments and then makiung a instance of the
>> corect object. the propble with this is that i have to do this on every
>> page. what i would like to do is load the same commonUserObject for each
>> user, and in the class then assign the right object as a child object. i
>> could then access the object like this
>>
>>
>> dim oUser as commonUserObject = new commonUserObject
>> oUser.childObject.someMethod
>>
>> This will do, but i was wondering if there was a more elegent way of
>> doing this, can i some how make the commonUserObject morph into the right
>> object.
>>

>
> You can make the specific user objects inherit your common user object,
> and use a factory method to create them:
>
> Dim user As CommonUserObject = CommonUserObject.Create()
> user.SomeMethod()
>
> The static Create method will create a specific user object depending on
> the conditions, but it's return type is still CommonUserObject.
>



thanks
sillly me , i had instance object in my mind and could think outside it.
thanks




> --
> Göran Andersson
> _____
> http://www.guffa.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a conditional assignment over generic or constant? sm.soimu@gmail.com VHDL 2 04-25-2006 10:00 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Conditional assignment to signals Johnsy Joseph VHDL 8 09-24-2004 11:02 AM
Comparison of Bit Vectors in a Conditional Signal Assignment Statement Anand P Paralkar VHDL 2 08-04-2003 08:40 PM
Help: conditional attribute assignment itsme VHDL 1 07-23-2003 03:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57