473,549 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with inheritance

Claus Mygind
571 Contributor
I am trying to create a custom object, with objects that have objects. My problem is with the last object in the chain (sample), rather than create an additional object for a new value it simply replaces the existing value.

More specifically this is the structure I am looking for:
(I have included two sample data sets and my code below)

Job (only one value)
Boring (one or more occurrences)
Sample(one or more occurrences)
sample properties (20 different properties for each sample)

74550
12
1
sampledate
depth
blows
.
.
.
2
sampledate
depth
blows
.
.
.

here is the sample data
Expand|Select|Wrap|Line Numbers
  1. "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
  2. "74550 12   1",74550,"12   ","1   ","2009-12-17","1-2.5      ","2-2-3      ","390","44.7","34.2","11.2","68.7","34.2","1087.7","1086.3","0.9","0.0","0.00","0.000","0.0"," ","","1.5        ",""," Black and Gray silty CLAY little sand trace gravel and organic very moist CL - FILL                                                                                                                                                                          ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  3. "74550 12   2",74550,"12   ","2   ","2009-12-17","3.5-5      ","2-3-3      ","391","56.6","46.5","11.1","77.8","46.7","1108.1","1086.1","0.8","0.0","0.00","0.000","0.0"," ","1.03 ","1.25       ",""," Brown +  Gray silty CLAY little sand trace roots very moist CL                                                                                                                                                                                               ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  4. "74550 12   3",74550,"12   ","3   ","2009-12-17","6-7.5      ","1-1-2      ","392","60.5","49.8","11.1","78.3","38.6","1107.5","1084.9","0.8","0.0","0.00","0.000","0.0"," ","0.50 ","0.50       ",""," Brownish Gray silty CLAY little sand very moist CL                                                                                                                                                                                                           ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  5. "74550 12   4",74550,"12   ","4   ","2009-12-17","8.5-10     ","1-2-2      ","393","53.3","42.4","11.2","74.1","31.4","1108.4","1086.3","0.8","0.0","0.00","0.000","0.0"," ","","0.25       ",""," Gray silty CLAY little sand very moist CL                                                                                                                                                                                                                    ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  6. "74550 12   5",74550,"12   ","5   ","2009-12-17","11-13      ","2-2-2-3    ","394","55.4","45.7","11.1","78.1","35.0","1108.7","1087.8","0.8","0.0","0.00","0.000","0.0"," ","0.63 ","1.0        ",""," Gray silty CLAY little sand trace organic very moist CL                                                                                                                                                                                                      ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  7. "74550 12   6",74550,"12   ","6   ","2009-12-17","13-15      ","5-6-7-8    ","395","65.2","58.8","11.1","88.2","26.7","1125.9","1109.9","0.7","0.0","0.00","0.000","0.0"," ","","2.5        ",""," Brown +  Gray silty CLAY little sand trace gravel moist CL                                                                                                                                                                                                   ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  8. "74550 12   7",74550,"12   ","7   ","2009-12-17","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","","","TEST SAMPLE                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  9.  

2nd sample data set
Expand|Select|Wrap|Line Numbers
  1. "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
  2. "74547 1    3",74547,"1    ","3   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown and Gray silty CLAY                                                                                                                                                                                                                                    ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  3. "74547 1    4",74547,"1    ","4   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown SILT                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  4. "74547 2    3",74547,"2    ","3   ","2009-12-21","","","32 ","54.2","44.7","10.3","27.6","44.5","1215.2","1193.1","96.5","0.0","0.00","0.000","0.0"," ","","","Corrected"," Brown clayey SAND trace gravel moist SC                                                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  5. "74547 3    3",74547,"3    ","3   ","2009-12-21","","","33 ","56.9","49.6","9.9","18.4","44.3","1213.3","1192.5","52.7","0.0","0.00","0.000","0.0"," ","","4.5+       ","Corrected"," Black silty CLAY little sand trace GRAVEL trace organic moist CL - FILL                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  6. "74547 4    3",74547,"4    ","3   ","2009-12-21","","","34 ","57.7","48.6","10.2","23.7","38.6","1210.8","1191.9","50.4","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand moist CL                                                                                                                                                                                                                ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  7. "74547 5    3",74547,"5    ","3   ","2009-12-21","","","35 ","61.4","54.3","10.1","16.1","34.4","1206.8","1191.2","53.7","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand trace gravel trace organic moist CL                                                                                                                                                                                     ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  8. "74547 6    3",74547,"6    ","3   ","2009-12-21","","","36 ","58.9","51.0","9.9","19.2","44.1","1210.9","1190.4","52.3","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown silty CLAY little sand moist CL                                                                                                                                                                                                                        ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  9.  
In my code below I can create the jobObject and a variable number of borings. But my "z" variable for creating the samples simply changes the existing sample on each loop.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. var JobObject = new createJobObj(aReturn)
  2.  
  3. function createJobObj(aData)
  4. {
  5.     //clientInfo
  6.     this.client = aData[0];
  7.     //jobInfo
  8.     this.job = aData[1]; 
  9.  
  10.     /*
  11.     ---------------------------------
  12.     create a boring array with sample 
  13.     data for each boring
  14.     ---------------------------------
  15.     */
  16.     this.boring = new Object();
  17.  
  18.  
  19.     for (var i = 2; i < aData.length; i++ )
  20.     {
  21.         var x = aData[i].substr(0,aData[i].indexOf('~'));
  22.  
  23.         if (x != this.boring)
  24.         {
  25.             this.boring[x] = new Object();
  26.         }
  27.  
  28.         //add sample data to boring element
  29.         aZ = new Array()
  30.         aZ = aData[i].split('~');
  31.         var z = aZ[1];
  32.  
  33.         if (z != this.boring[x])
  34.         {
  35.             this.boring[x][z] = new Object();
  36.         }
  37.         this.boring[x][z].sampleDate = aZ[2];
  38.         this.boring[x][z].depth = aZ[3];
  39.         this.boring[x][z].blows = aZ[4];
  40.         this.boring[x][z].contNumb = aZ[5];
  41.         this.boring[x][z].WWofSC = aZ[6];
  42.         this.boring[x][z].DWofSC = aZ[7];
  43.         this.boring[x][z].contWeight = aZ[8];
  44.         this.boring[x][z].moisture = aZ[9];
  45.         this.boring[x][z].sampleInAir = aZ[10];
  46.         this.boring[x][z].sampleInWater = aZ[11];
  47.         this.boring[x][z].water = aZ[12];
  48.         this.boring[x][z].dryUnit = aZ[13];
  49.         this.boring[x][z].corrected = aZ[14];
  50.         this.boring[x][z].dimDryUnit = aZ[15];
  51.         this.boring[x][z].dimCorrected = aZ[16];
  52.         this.boring[x][z].qu = aZ[17];
  53.         this.boring[x][z].qp = aZ[18];
  54.         this.boring[x][z].soilDesc = aZ[19];
  55.     }
  56. }
  57.  
Jan 4 '10 #1
4 1500
Dormilich
8,658 Recognized Expert Moderator Expert
I think it’s line 23. you check, whether this.boring equals x, but you certainly mean, whether x is a subobject of this.boring. (same goes for line 33)

there are 2 ways on my mind:
Expand|Select|Wrap|Line Numbers
  1. if (!(x in this.boring)) {}
  2. if (!this.boring[x]) {} // except if this.boring[x] may be 0, "", false, null, [] or {}
Jan 4 '10 #2
Claus Mygind
571 Contributor
Of course you are correct, I am looking for a subObject. I had to run the simulation several times before I saw that my problem occurred on line 23.

I don't seem to be experiencing the problem on line 33 as you suggested and I was having some trouble implementing your suggestions (I believe you say I should use your line #2?

I am not clear on how I should test for the exceptions you have listed. And on the first go around the subObject has no properties so of course it crashes.
Jan 4 '10 #3
Claus Mygind
571 Contributor
I see my error. Just repeat your line 1 on my line 33

Expand|Select|Wrap|Line Numbers
  1. if (!(z in this.boring[x]))
  2.  
Jan 4 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
I believe you say I should use your line #2?
no, both basicly (see comment) do the same.

and to be precise, your problem has nothing to do with inheritance, that would involve meddling with the prototype property.
Jan 4 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

18
1955
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point to the parent in the inheritance tree). 2. This hierarchy evolved over time to different versions for each class. So for example, version's 1...
4
2887
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common...
3
2459
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. My problem is that I have a /third/ class, CCommand, which derives from both IControl and ICommandmaster... The error message says (Weird.....)
0
1110
by: Bita-kookoo | last post by:
I am having a problem with inheritance for my web solution. Here are the steps I took for a project within C#: -I first created a new class, descended from System.Web.UI.Page. For this description, let's call this class "MyBasePage". Every webform page within my solution will descend from this class instead of System.Web.UI.Page. The...
1
1191
by: Galileo | last post by:
I want to ask some questions about ASP, but not ASP. NET, sorry for my cross post because i don't know where asp newsgroup is First, is it possible to use user defined class in ASP, if so, how? and does ASP support something like inheritance? I know vb only support something like interface, is it the same as ASP? Is there any example for ASP...
0
973
by: Mariano | last post by:
Hi, I have posted a bug of the forms designer that overwrites always the Icon, thus preventing Icon inheritance when you derive from a form. I am trying to overcome this by adding an ImageList in the base class. However, this doesn't solve my problem about Icon inheritance. The idea is to put Icon showing code inside the base form class. I add...
9
3290
by: surendran.d | last post by:
hi, can diamond inhertance problem be solved using virtual functions,, or can only be done with scope resolution operators.. is there any other way to solve this problem... Thanks, suri
14
3583
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n should not be. But if I compile with g++-4.0.3 the following snippet: class A { int i;
9
10956
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
3
2888
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table: tlkpColor (PK) tlkpColorID
0
7451
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...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
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...
0
6048
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...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5089
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...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
766
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...

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.