Prev | Current Page 250 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Another typical use case for interfaces is in the definition of a layer of abstraction over a low - level
system; in haXe this type of abstraction is found in the neko.db.Connection interface that defines a
generic and interchangeable approach to connect to a database. All databases, independently of their
origin, perform some common tasks: executing queries, connecting to a data source, and so on. Those
common tasks are implemented in very different ways that depend on the vendor choices. To unify the
behaviors of different libraries and, thus realize the layer of abstraction, it is necessary to write some glue
codes. This code will contain functions that wrap the original API and map those functionalities in a
class implementing the neko.db.Connection . In this way, it is possible for example, to use MySQL and
SQLite exactly in the same way and more importantly in an exchangeable way. When it is needed to
switch from a db to another, it is enough to change the instantiation line.
Advanced Classes and Objects Features
Sometimes accessing methods and variables directly is not a viable solution; you may need more
flexibility in accessing private members or you may not know which field has to be accessed until a few
moments before that happens.


Pages:
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262