Libzypp/Design/Resolvable/Creating

Şuraya atla: kullan, ara

Creating Resolvables

This looks a bit more complicated as it actually is.

  • Dependent on the kind of source, there may be different needs on how to

retrieve and store the object related data. Not everything is provided by each kind of source. Not everything can be stored inside the object. Less important stuff may be retrieved on demand.

Thats why we have an interface description which defines which data a e.g. Packages provides, and leave it up to the source to realize this. I.e. to provide an implementation of this interface, which cooperates with the source to efficiently (memory consumption vs. speed) provide the data.

The native approach would be something like this:

class Resolvable
{
public:
// Vital and frequently used data are stored within and
// provided by Resolvable.
string name()    const { return _name; }
string edition() const { return _edition; }
...
private:
string _name;
string _edition;
...
};

Interface:


class ResObject : public Resolvable
{
public:
// Common object attributes. Stuff every kind of Resolvable
// should provide, mainly to make the User and the UI happy.
// If posssible providing reasonable defaults, in case the
// concrete class can't provide better values.
virtual string summary()    const { return ""; }
virtual string description() const { return ""; }
...
};
class Package : public ResObject
{
public:
// Package specific attributes. Either providing default
// values or pure virtual, if the concrete class MUST
// implement them.
virtual string morePackageData() const { return ""; }
virtual string specialPackageData() const = 0;
...
};

Implementation:


class MyPackageImplementation : public Package
{
public:
// Realize the interface and contains actual data.
virtual string summary()            const { return _summary; }
virtual string description()        const { return _description; }
...
virtual string morePackageData()    const { return _morePackageData; }
virtual string specialPackageData() const { return _specialPackageData; }
...
private:
string _summary;
string _description;
...
string _morePackageData;
string _specialPackageData;
...
};

Q: Why not that simple?

A: It is almost that simple, almost.


back

Last edit in Trac '11/24/05 18:26:26' by 'kkaempf'


Last edit in Trac '11/24/05 18:26:26' by 'kkaempf'


Last edit in Trac '11/24/05 18:26:26' by 'kkaempf'


Last edit in Trac '11/24/05 18:26:26' by 'kkaempf'