business layer functionality in data layer

Discussion in 'C++' started by Deodiaus, Oct 12, 2010.

  1. Deodiaus

    Deodiaus Guest

    I am looking for example of source code (preferably open source)
    which
    exhibits a good design pattern to break up my functionality into 3
    layers, a presentation layer, a business layer, and a data layer.
    Mostly, I am looking for a data layer API which is able to deal with
    data stored either in a file system like that used by dBase (v5) or
    [MS] SQL layout.
    I am writing my code in C++!

    Right now, I am trying to build the functionality to hide the data
    representation
    I am getting into lots of problems deciding which data should go into
    which layer.

    When querying Google, I see lots of articles long on top level design
    details, but very little source code.

    I like
    http://msdn.microsoft.com/en-us/library/Aa581778
    but he does a poor job of hiding the data layer's members from the
    business layer!

    Can anyone point me to a URL meeting these criteria.
    This newsgroup has some smart people, so if you know of another group
    more appropriate to my question, please redirect me.
    Deodiaus, Oct 12, 2010
    #1
    1. Advertising

  2. Deodiaus

    MiB Guest

    On Oct 13, 12:00 am, Deodiaus <> wrote:
    > I am looking for example of source code (preferably open source)
    > which
    > exhibits a good design pattern to break up my functionality into 3
    > layers, a presentation layer, a business layer, and a data layer.


    Actually, I have not encountered any distributed application accessing
    a database that does /not/ follow this design pattern (3-tier).
    However, this is a *pattern*, not a *framework* and example code will
    give you limited help only --- like technical things on how to realize
    database connectivity. There will be oh-so-many design decisions that
    depend on your concrete task at hand and you do not see that easily
    from other people's code. For example you will not see alternative
    approaches considered for any detail and the reasons why the
    implemented ones were favored over the alternatives.

    I would recommend studying a book, my over the top favorite on this
    topic is Martin Fowler, "Patterns of Enterprise Application
    Architecture", Addison-Wesley (2003). A major part of it covers your
    problem in-depth, in very understandable language. The example codes
    given in the book are C# and Java but it should be very easy to adapt
    to C++ --- it is dealing with patterns, not implementations.

    > Mostly, I am looking for a data layer API which is able to deal with
    > data stored either in a file system like that used by dBase (v5) or
    > [MS] SQL layout.
    > I am writing my code in C++!


    C++ does not offer any database access as part of the standard. You
    most likely will have to resort to platform specific libraries. ODBC
    is reasonably widely available, but feels too low level --- you'd
    still need to embed SQL statements into your code and given the
    miserable state of interoperability of current databases at SQL level,
    I cannot really recommend it.
    Currently I am working with Microsoft's Entity Framework giving me an
    abstraction layer for any data tier with an ADO.NET adapter (eg. SQL
    Server, Oracle, XML, and some more). This would limit you to .NET
    platform, and C++.NET is not standard C++.
    Maybe some other friendly person in this news group can hint to a C++
    equivalent of Java's hibernate or Entity Beans frameworks.

    > Right now, I am trying to build the functionality to hide the data
    > representation
    > I am getting into lots of problems deciding which data should go into
    > which layer.


    I usually start with a UML domain model, analyzing the data my
    application needs to deal with at real world level. A car is a car in
    this view and not a join on many tables where one is representing
    wheels and others welding connections. The domain model purposely
    represents my data denormalized. I next derive two completely
    different refinements from this, first the database model (normalizing
    the data, selecting database specific datataypes) and the data object
    model, i.e. how I like the data be represented as class instances in
    my application (using pointers, native and STL datatypes).
    How these two interact is a complex design decision, read Martin
    Fowler's book mentioned above.
    Most of the time I want to have a database layer that deals with data
    strictly in database format and offers a generic interface to the
    upper layer. This will be an implementation specific to the DB
    management system and you'd need to create one for SQL Server, one for
    dBase and one for each DB you might want to add on top. On the other
    side I do a business layer that does not care about how data is stored
    in any DB and acts only on the data object model.
    So actually, I put most of the involved data into my designs *twice*
    (actually, three times, I do the same approach for GUIs, defining a
    user visible representation of my data, independent of the business
    tier, see Model-View-Controller [MVC] pattern).
    So its not really a question of what data to put where but rather how
    to communicate the different representations of the same data between
    layers.

    > When querying Google, I see lots of articles long on top level design
    > details, but very little source code.


    Looks like most other people feel the same about this topic as me :)

    [..]
    > Can anyone point me to a URL meeting these criteria.
    > This newsgroup has some smart people, so if you know of another group
    > more appropriate to my question, please redirect me.


    I am sorry I cannot be more specific, but I really feel specifics
    would do you no good anyway.

    best regards,

    MiB
    MiB, Oct 13, 2010
    #2
    1. Advertising

  3. Deodiaus wrote:
    > I am looking for example of source code (preferably open source)
    > which
    > exhibits a good design pattern to break up my functionality into 3
    > layers, a presentation layer, a business layer, and a data layer.
    > Mostly, I am looking for a data layer API which is able to deal with
    > data stored either in a file system like that used by dBase (v5) or
    > [MS] SQL layout.
    > I am writing my code in C++!
    >
    > Right now, I am trying to build the functionality to hide the data
    > representation
    > I am getting into lots of problems deciding which data should go into
    > which layer.
    >
    > When querying Google, I see lots of articles long on top level design
    > details, but very little source code.
    >
    > I like
    > http://msdn.microsoft.com/en-us/library/Aa581778
    > but he does a poor job of hiding the data layer's members from the
    > business layer!
    >
    > Can anyone point me to a URL meeting these criteria.
    > This newsgroup has some smart people, so if you know of another group
    > more appropriate to my question, please redirect me.


    Search for "presenter first". I am sure you will get lots of hits with
    code, and if lucky, you might even find c++ example.
    Vladimir Jovic, Oct 13, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. et
    Replies:
    2
    Views:
    1,877
  2. dan
    Replies:
    25
    Views:
    1,308
    Uncle Bob (Robert C. Martin)
    Oct 28, 2003
  3. java-john
    Replies:
    0
    Views:
    518
    java-john
    Mar 23, 2006
  4. Dhananjay
    Replies:
    1
    Views:
    1,089
    sloan
    Dec 18, 2006
  5. SAL
    Replies:
    9
    Views:
    496
    Steven Cheng[MSFT]
    Jan 14, 2008
Loading...

Share This Page