Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > How does one execute parent class code when calling a child method?

Reply
Thread Tools

How does one execute parent class code when calling a child method?

 
 
Noozer
Guest
Posts: n/a
 
      02-07-2006
I have two Classes in use in an ASP application...

The first Class is named "ORDER". It represents one job order. It has a
Delete method, among others, which deletes it from my database.

The second Class is named "ORDERS". It represents a collection of ORDER
objects. Basically an array of ORDER objects. It has a Remove method that
JUST removes the ORDER object from the collection - no data is erased.


If I execute ORDERS.Item(3).Delete, I'd expect that the ORDER with an index
of 3 would be deleted from my databse - BUT the ORDER object would still be
in my ORDERS collection class.

How can I have the ORDERS Class execute code to remove the ORDER, when I
execute the ORDER.Delete method?

I could write a Delete method in my collection class, but that's not very OO
friendly.


 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      02-07-2006
Noozer,

Are you sure you want to be doing 'OO friendly' things in such a OO hostile
environment??

VB Script is far from the best language to build OO designs in.

The objects that you have been talking about in various posts seem fairly
stateful. However they only live as long as single request (unless you are
storing them in the Session which is seriously not recommended), which means
that the bulk of server activity is likely to be the creation, loading and
destruction of objects rather than any actual work.

To answer you question: For the Order object to remove itself from it's
parent Orders object it would need to have a reference to this object.
Since Orders will have a reference to this child Order object you end up
with a circular reference. Circular references are likely to lead to memory
leaks so are not recommended.

I would suggest that you have a Delete method on the Orders object which
Removes the Order then calls it's Delete method. Why do you think that this
isn't OO Friendly?

Here are some other things you might consider:

build your object hierarchy in VB6 rather than VB Script you will be able to
do the sort of things you want (like delete method removing from a
collection) and it'll be faster.


if you must use a script language to deliver a OO design then Javascript
would be a better choice.


Anthony.


 
Reply With Quote
 
 
 
 
Noozer
Guest
Posts: n/a
 
      02-07-2006
> Are you sure you want to be doing 'OO friendly' things in such a OO
> hostile
> environment??


Because, hopefully, it will make my life easier in the long run.

I've dabbled in many languages (6809 assembler, dBaseIII, Clipper, QBasic,
VB, HTML, ASP...etc.) It's becoming VERY fuzzy as to what technology you use
when designing a solution. I'm trying to build a web based tracking system
using an MS SQL database.

> To answer you question: For the Order object to remove itself from it's
> parent Orders object it would need to have a reference to this object.
> Since Orders will have a reference to this child Order object you end up
> with a circular reference. Circular references are likely to lead to
> memory
> leaks so are not recommended.


If I create an ORDER object and use it, it shouldn't need or have any
reference to any Orders object. (Man, I should have used better names for my
example)

But, if I create an Orders object, it may contain many ORDER objects. Can't
I overload (???) the Delete function in the ORDER object with a method in my
Orders object?

> I would suggest that you have a Delete method on the Orders object which
> Removes the Order then calls it's Delete method. Why do you think that
> this
> isn't OO Friendly?


If I wan't to delete an ORDER, why would I ask the Orders to do it?

Hmm... I guess that it's not reasonable to expect an Orders object to notice
when I delete an ORDER object that isn't a child of the Orders object. I'm
still green enough to expect OO objects to behave like real world objects.
(ie. Delete a record in the database to affect any object that is related to
that data)

> Here are some other things you might consider:
>
> build your object hierarchy in VB6 rather than VB Script you will be able
> to
> do the sort of things you want (like delete method removing from a
> collection) and it'll be faster.


But how will this function when served to a web browser from an IIS server?

> if you must use a script language to deliver a OO design then Javascript
> would be a better choice.


Possibly, but I know much less about javascipt than vbscript.

....I'm just having problems getting Concept into Code.


 
Reply With Quote
 
Noozer
Guest
Posts: n/a
 
      02-07-2006
> The objects that you have been talking about in various posts seem fairly
> stateful. However they only live as long as single request (unless you
> are
> storing them in the Session which is seriously not recommended), which
> means
> that the bulk of server activity is likely to be the creation, loading and
> destruction of objects rather than any actual work.


Out of curiousity... What would you use to create a web browser based
application that would have a small (20?) number of clients using it at any
time controlling a database that could eventually contain hundreds of
thousands of records (containing text, numeric and date/time information -
no binaries)



> I would suggest that you have a Delete method on the Orders object which
> Removes the Order then calls it's Delete method. Why do you think that
> this
> isn't OO Friendly?


I just thought of something... If I remove the Order object from the
collection, won't it be gone and unavailable for the ORDER Delete method?

This is the code from my Orders collection object

'-- Delete an item in our collection from the DB ------------------------
Public Function Delete(idx)

Dim i 'General counter

'Default is FAIL
Delete=False

'Remove from our collection, and delete from database if we were
successful.
if Me.Remove(idx) then
'Delete Order from database
Me.Item(idx).Delete
'Success
Delete=True
End If

End Function

'-- Remove an item from our collection ----------------------------------
Public Function Remove(idx)

Dim i 'General counter

'Default is FALSE = Fail
Remove = False

'Raise an error if there are no elements at all
If Me.Count=0 Then
Err.Raise 1, "No objects in collection"
Else
'Test for a valid index...
If idx<lBound(vCollection) Or idx>=uBound(vCollection) Then
'..and error if not
Err.Raise 1,"Out of bounds"
Else

'If we aren't removing the last item so we need to move the
' elements down to fill the gap
If idx<uBound(vCollection) Then
For i=idx TO uBound(vCollection)-1
Set vCollection(i) = vCollection(i+1)
Next
End If

'If we are removing the last element, completely clear array
If ElementCount(vCollection) = 1 Then
Dim vCollection()
Else
'Shrink the array holding our collection
ReDim Preserve vCollection(uBound(vCollection)-1)
End If

'Success
Remove = True

End If
End If

End Function



 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      02-07-2006
>If I create an ORDER object and use it, it shouldn't need or have any
>reference to any Orders object. (Man, I should have used better names
>for my example)


Agreed. An Order object could be a standalone object and it's best that it
doesn't need to own a backreference to a parent.

>But, if I create an Orders object, it may contain many ORDER objects.
>Can't I overload (???) the Delete function in the ORDER object with a
>method in my Orders object?


No.

>Hmm... I guess that it's not reasonable to expect an Orders object to

notice
>when I delete an ORDER object that isn't a child of the Orders object.


Ok. An Orders object could be an aribitary collection of Order objects.
In this case you wouldn't want the Orders collection to have a delete
method. The Observer pattern could be used in such a case which would allow
the Order object to notify any Orders objects (the could be more than one)
that it has been delete. I don't think it can be done in VBScript.

>I'm
>still green enough to expect OO objects to behave like real world objects.
>(ie. Delete a record in the database to affect any object that is related

to
>that data)


OO object will behave just as you have programmed it to. Just as deleting a
record in database only performs the checks, cascades and triggers you've
programmed it to. It's not magic pixie dust.

>But how will this function when served to a web browser from an IIS server?


Umm... This is the ASP group. We are talking VB Script on the server side
aren't we. Come to think of it this whole discussion would make more
sense if we were discussing client side script.

>Possibly, but I know much less about javascipt than vbscript.


>...I'm just having problems getting Concept into Code.


If in fact we have got our wires crossed and we are discussing Client side
script then Javascript would be the language of choice because it provides a
better platform to deliver an OO design.

Anthony.






 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      02-07-2006
>Out of curiousity... What would you use to create a web browser based
>application that would have a small (20?) number of clients using it at any
>time controlling a database that could eventually contain hundreds of
>thousands of records (containing text, numeric and date/time information -
>no binaries)


There is a lot information missing to be definitive. For example why is it
web based in the first place? Is there intensive number crunching involved
or is it a data entry and report style of application? How complex are the
business rules?

My approach (in admittedly larger requirements) is to use a lot of
javascript and OO techniques clientside in the browser in a vain attempt to
shore up the browsers woeful UI experience. I treat ASP as two different
things: 1) Mechanism to deliver the UI to the client; 2) an API through
which to communicate with the 'business logic'.

I use XML to store object state (client side javascript objects wrap round
XML elements) and the transport for client-server comms. Ultimately XML
ends up being processed by SQL Server. I use VB6 Components serverside to
ease DB operations and XML munging (but not for business objects).

>I just thought of something... If I remove the Order object from the
>collection, won't it be gone and unavailable for the ORDER Delete method?


See the other post.

Anthony



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Query regarding calling parent's class method which is overridden in child class??? parkarumesh@gmail.com Java 2 04-26-2007 09:34 PM
Query regarding calling parent's class method which is overridden in child class??? parkarumesh@gmail.com Java 0 04-26-2007 09:24 AM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM



Advertisments