0

As a coding test I've been tasked with developing a toy three-layer architecture DBMS project, involving OOP principles. The three-layer stuff isn't strictly my background so I've been trying to study what a barebones conceptual implementation of that looks like.

I think I understand the general nature of the three layers themselves: a presentation layer communicates with the business-logic layer, which in turn communicates with a data-access layer. Interfaces are used for greater flexibility here: that is, the business layer might be given access to something implementing a data-layer contract, with no specific knowledge of what that implementation looks like.

(Presentation Interface) -> (Business Interface) -> (Data Interface)

What's been difficult to research beyond that, is: suppose I'm coding something up involving deliveries (arbitrary example). The presentation layer is occupied with displaying the particulars of delivery orders. The business layer enforces the rules of e.g. making or modifying deliveries. The data layer stores the delivery info as set and retrieved by the business layer.

Well, there needs to be a coherence between all of these in what all three layers understand a "delivery" to be, right? The business layer's internal Delivery class needs to be compatible with the data representation of the delivery, and so in that sense I'd say roughly that both Business and Data (and Presentation, for that matter) depend on a Delivery component.

Presentation----\

Business----------> Delivery, etc

Data-------------/

Except, that seems unintuitive to me. If you imagine what the dependency graph here would look like after throwing in a dozen more of these concepts, it very quickly seems to look lopsided and focused on the implementation details of minutiae.

And yet I have seen indications that connectors between the layers do exist on a class-by-class basis (e.g. CRUD Repositories), so is it just something that's accepted?


The other thing I can think of would be to define concrete "Delivery Data" that the Data-layer interface is forced to accommodate one way or another, and that the Business-layer's delivery class also derives from:

(Business Delivery Class) -> (Pure Delivery Data)

I understand there are a bunch of different ways of implementing these architectures (partially why this has been difficult to study), so I guess I'm looking for a broad intuition of how the dependencies are intended to resolve as the conceptual scale starts to increase. Thanks!

1 Answer 1

0

The diagram

(Presentation Interface) -> (Business Interface) -> (Data Interface)

is not wrong, but only represents the typical run-time graph. In Clean Architecture, and similar styles of architectures, the dependency graph rather looks like this:

(Presentation Interface) -> (Business Interface) <- (Data Interface)

A subtle, but important distinction.

So if you want to define data structures as part of your Domain Model (e.g Delivery), you'd have to put it in the Business Interface if you want to make it available to the other layers.

My article Decomposing CTFiYH's sample code base contains an overview of what goes where, and there are plenty of links from that article to further reading.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.