Re: Constructor chaining

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Sidharth" <Sidharth@xxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de
news: BF77C7A4-BA2E-42C8-9BC8-99C3E1B0E5A4@xxxxxxxxxxxxxxxx

| Thanks for the reply. It's a very clever solution but I feel it may not be
| viable in my situation. I should've provided more information in the first
| place, sorry. What is happening is the constructor is doing 2 things:
| creating the details in the database and then initiating the object
itself.
| So originally I had only one constructor for the class:

Pardon me for saying so, but this really is not a good idea. You are tying
your business objects to a database that could change, thus forcing you to
have to change all your business classes whenever that kind of thing
happens.

Take a look at separating your business classes from their storage using
something known as an OPF (Object Persistence Framework). These creatures
use reflection to examine objects and store/retrieve/delete them from a
database without the objects knowing anything at all about databases. They
really are a better way to go.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


.



Relevant Pages

  • Re: Simple (?) Singleton Question
    ... actually being created with each request. ... Wherever you need the singleton, you just have to call the getInstance ... I might have several business classes which access tables in the database. ... The singleton class for the database means each of the business classes can get the one instance of the database class. ...
    (comp.lang.php)
  • Re: [PHP] See if this makes any sense
    ... You do *NOT* want to re-connect to the database on every InsertDB! ... Do that once in the constructor and be done with it for as many ... function dBInsert($table, $sql) ...
    (php.general)
  • Re: Object Design Best Practice
    ... say I have the following tables in my database: ... connection string into the constructor to load the object using data ... You should have your business layer call your data access layer, ... If so, should I load the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: load event vs constructor?
    ... I was used in VB6 to put code in Forms load event in order to initialize ... database. ... your constructor should run as quickly as possible ... which runs on a background thread and does the database fetches. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Object Design Best Practice
    ... not the existing database. ... Should I load ALL of the object's properties ...? ... They'd still get the connection string from their config ... connection string into the constructor to load the object using data ...
    (microsoft.public.dotnet.languages.csharp)