473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Feb 7 '06 #1
5 1945
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.
Feb 7 '06 #2
> 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.
Feb 7 '06 #3
> 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).De lete
'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(vCol lection) Or idx>=uBound(vCo llection) 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(vCol lection) Then
For i=idx TO uBound(vCollect ion)-1
Set vCollection(i) = vCollection(i+1 )
Next
End If

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

'Success
Remove = True

End If
End If

End Function

Feb 7 '06 #4
>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 noticewhen 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 tothat 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.


Feb 7 '06 #5
>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

Feb 7 '06 #6

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

Similar topics

2
3867
by: lkrubner | last post by:
My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed(); $this->arrayOfAllTheObjectsSoFarLoaded = & $object; if (method_exists($object, "setCallingCode")) $object->setCallingCode($nameOfFunctionOrClassCalling); return $object; } else {
5
27590
by: Paul | last post by:
Hi all, Here is what I am trying to do. I have a parent class calling a child class. when one function in child class is called, i need to call parent class' function. How can I get parent class' pointer? Thx Paul
6
10966
by: jalkadir | last post by:
Let's say that I have this class: class Parent{ private: char* str; public: const char* getStr(){return str;} }; And then I create a child class class Child{ private: std::string str; public: std::string& getStr(){return str;}
2
4848
by: Kelmen Wong | last post by:
how to work out a design to enable a child object to call its parent(creator/container) method/property? Its easy to be done if the child can know/assume its parent, but in my scenario, many different object can create the same child object, means the child object's parent is dynamic. Event is possible, but I need the process in synchornous, as event process is in asyn.
3
9690
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
7
2029
by: msxkim | last post by:
How to execute functions in the parent class first and then functions in the child class? For example, I have a parent class with functions 'ONE' and 'TWO' and child class has a function 'THREE'. How should I declare classes so that all three functions are executed when child class is called? Class Parent public function ONE 'code end fuction
10
19602
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public Class Parent '*** HOW TO DECLARE IT *** Dim Age As String = "1/1/2000"
3
1284
by: kirknew2SQL | last post by:
I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. 1. initTreeView(TreeNode N) creates a new “temp” table to hold the children for each node. Each time the table is created it has the same name “temp”. Why doesn’t the table just get over written each time? 2. In the foreach (DataRow r3 in temp.Rows) loop, if the temp table is empty like when Menu11 is reached the...
3
293
by: xmail123 | last post by:
Why does this code work? I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. I have two questions about why this code works. 1. initTreeView(TreeNode N) creates a new "temp" table to hold the children for each node. Each time the table is created it has the same name "temp". Why doesn't the table just get over written each time? 2. In the foreach (DataRow r3...
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7203
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.