473,412 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Problem with inheritance

Claus Mygind
571 512MB
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

✓ answered by Dormilich

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 {}

4 1494
Dormilich
8,658 Expert Mod 8TB
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 512MB
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 512MB
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 Expert Mod 8TB
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
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...
4
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...
3
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. ...
0
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...
1
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?...
0
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...
9
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
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...
9
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
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:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.