[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

"Delphi Object Model" ?

Dear fellow experts,

I went for a job assessment today and unfortunately had to give up because I couldn't understand what they were trying to do.
As a developer (and "expert") I like to believe that I can "do anything" even if I have to do a bit of research, this was one of those cases where I'm ashamed to say I haven't really had much experience doing and couldn't understand exactly what they were asking for...

The brief asks to create a data/delphi "Object Model" to be able to take files from two mining companies, and be able to "add, insert, and delete records in an Access database, using ADO". The Access database was already created so (I assume) it's a matter of converting the data in "files" from the mines to fit uniformly in the database, BUT, through an "Object Model".
* A mdb file (Access file) was provided with 2 empty tables: 1 table was "Mineworkers", 1 table was "Dependants".
* They did *NOT* provide a sample of the "files" that would be received from the mines, buy they did say what order the fields would be received in, e.g. they said mine 1 would put fields in this order: EntityID, Surname, Firstname, and mine 2 would put fields in this order: EntityID, Date Of Birth, Surname, Firstname, etc.

So here's what I did:
In my unit I declared 2 classes, one was TMineworker and one was TDependant.  In each class I declared each field as a string, here's an example:
type
  TMineWorker = record
    EntityID : string;
    Surname : string;
    Firstnames : string;
    DateOfBirth : tdate;  
  end;
  TMineWorker = record
    EntityID : string;
    Surname : string;
    Firstnames : string;
    DateOfBirth : tdate;  
  end;

..and that's where I left it. I had two problems:
1) I had no idea what these "files" from the mines looked like. They could be xml files, csv files, etc
2) I couldn't understand why they needed an object module between the files and the database. I would just process the "files" and pump them directly into the database .

Can you experts please enlighten me as to where I went wrong and what they were looking for.

I am so incredibly ashamed... Should I kill myself now, or later?

Thanks as always!!!
0
rfwoolf
Asked:
rfwoolf
  • 4
  • 3
  • 2
  • +2
7 Solutions
 
SteveBayCommented:
Well I believe in this case "Object Model" may be a somewhat vague term. However that said; perhaps a class definition more like this would have been more satisfactory
This is more along the line of how I typically approach this sort of requirement.

type
  TMineWorker = class(TObject)
  private
    FEntityID: string;
    FFirstnames: string;
    FSurname: string;
    FDateOfBirth: tdate;
    procedure SetDateOfBirth(const Value: tdate);
    procedure SetEntityID(const Value: string);
    procedure SetFirstnames(const Value: string);
    procedure SetSurname(const Value: string);
  Public
     property EntityID : string read FEntityID write SetEntityID;
     property Surname : string read FSurname write SetSurname;
     property Firstnames : string read FFirstnames write SetFirstnames;
     property DateOfBirth : tdate read FDateOfBirth write SetDateOfBirth;
     function LoadFromFile(FileName : String) : Boolean;
     function SaveToDatabase : Boolean;
end;

Open in new window

0
 
rfwoolfAuthor Commented:
That's great Steve, that all makes a great deal of sense. Can someone perhaps explain why on earth it might be necessary to have an object model in the first place? Why not use the Database?
0
 
developmentguruCommented:
 Unfortunately technology is almost always managed by people who do not understand it.  I have had managers tell me that they want an object model to accomplish a goal... only to find out that they had picked up on an article on object oriented programming and presumed that was the "way to go".  In your case I would simply create a class that handles the import of data for each type of input.  Of course, you will need to have example data to work with (or at least a specification) in order to ensure the code works.  This goes to requirements gathering.  You do not have a clear set of requirements yet.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rfwoolfAuthor Commented:
Thanks developmentguru, I feel at least 5% better although I still don't understand - when I started reading about this stuff years ago, records were things in QBasic that you used in place of a database to store these records in files. Now it's 2009 and I'm expected to store data in objects only to later put them into databases. We have all the tools we need in the form of components to both validate and input the data to all of the requirements they had in the brief. In my (perhaps foolish) mind this is more in the area of component writing - something I have specifically avoided for a long time. SteveBay's post makes absolute sense to me but I've never had to write it.
They did try to explain that they have about 20 "systems" and so they need someone with object orientated programming skills to be able to have the systems work together. Does that explain to you why they would need an object model?  I still can't make the connection.
0
 
SteveBayCommented:
The reason I use objects to handle data is that it make my code easier to maintain in the long run. I also avoid data-aware controls in anything other than the simplest of applications. In the example above you can see from the definition where the load and save rouines are and you can jump to them (in the Delphi IDE) with a CTRL-SHIFT Click.
No doubt, it take s longer to develop the initial code but when I look at it 3 years from now it will be organized in a way that makes it easy to locate problems and make changes/enhancements. I have some Delphi projects that go back 12 years that are as easy to read as code I worte 2 weeks ago. Keeping data in objects forces me to have organized easy to read and maintain code.
0
 
rfwoolfAuthor Commented:
That's interesting. And so then in this example you would create an instance of a TMineworker object, load from the file, save to the database, and then destroy/free it? I can see that it would nicely organise the code, but I fail to see other benefits. I could imagine for example a visual chart that isn't data-aware that would like to be fed an array of objects and this is a way of doing it. I suppose in their case if they have 20 "systems" but their data formats are all out of synch, I think I can see how an object model would be mildly beneficial. I think I get it now. :p
0
 
developmentguruCommented:
 Steve Bay's comments are well said.  There is a lot to be said about creating readable, reusable, code.

  I  do not think this pertains to the request you have been given though.  I still think that it goes to a simple lack of understanding on their part in how they are trying to communicate to you.

  Personally, for this type of application, I would expect to need to do a custom parser if the data you get from several sites is going to be THAT different.  Even then, if they are typing it in by hand, you will run into errors when trying to import the data.  If this is the case it may be simpler to have a base object that contains the fields and a pair of abstract methods for load and save (or one for import).  Then you can make a separate, descendant object for each type of input you will get and make it specific for that type of input.  This can avoid the extra work of doing a custom parser and keep the code easier for someone else to follow.

  I have written code to take a database field (a memo field) that could contain one or more of 27 embedded values in no particular order (free form text), parse it following a set of rules, and strip out the meaningful data into other database fields.  This is an instance where the data is not in any particular order and may or may not exist.  While the project was able to handle several hundred records per second, hopefully your project will not be that difficult.

  It all comes back to getting more specific requirements (I.E. test data).

0
 
SteveBayCommented:
I should add that OOP aids in group development as well. I work in a small group and we frequently have to share development or hand-off projects to one-another. A *well" written class *should* be self-documenting thereby reducing the communication required between team members when working on each others code. Well written means using meaningful property and method names and following some standard layout conventions. The VCL is loaded with great examples of standard conventions.
0
 
EddieShipmanCommented:
That reminds me of when I went to the interview for my last job. They used VB.Net and they always have the applicants perform a test to modify a "Duck" to make it squeak, make it a rubber duck, etc. They got the example from some .Net book. I aced it in 5 minutes. They said that all the other applicants had taken at least 30 min to do the test and most didn't even understand the concept of object inheritance.

I got the job even though I knew no VB.Net.
0
 
aikimarkCommented:
Take a look at ECO (Enterprise Core Objects).  This is a good example of objectifying database tables.  This is not the only product to do this kind of objectification, but is associated with Delphi.

Here's a scenario...your developers can use any desktop storage mechanism to test their code.  With little effort, the object code can be changed to talk to an enterprise database or other storage mechanism.

If a company was developing a software product that used a database, it would be advantageous to add this object layer to the application, allowing the application to run in many different customer environments with different databases.  
0
 
rfwoolfAuthor Commented:
Thanks to all. I have awarded points as best I can, thank you for taking the time to contribute your thoughts.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now