PHP Page 3 - Building Object-Oriented Database Interfaces in PHP: Working with Multiple Data Access Objects |
Once we've called the "generate()" method, one data access object $user has been programmatically created. But let's go one step further: if the object is available to be used, there must be a class from which the object was properly instantiated. That's the main task of this generator class, as you might guess. One DB Interface class has been generated "behind the scenes," providing a bridge between the database table and the application logic. As you've seen before, this is the class that I obtain as a result, after executing the above code: class User{ Definitely, the "DBIGenerator" class does its thing building the corresponding database interface class for a specified database table. In this case, I'm showing a more readable version of the code generated, since in its obfuscated version, it doesn't contain any new lines. However, this is not a relevant issue for the PHP interpreter. Well, happily we've seen how a simple code generator works, because we have a class that is capable of generating one or more classes, according to the particular application requirements. Do you realize the actual power of this approach? I guess you do. However, let's implement some examples to see how a database interface can be put to work for us.
blog comments powered by Disqus |