9 Nisan 2019 Salı

Domain Driven Design

Giriş
Domain Driven Design (DDD) yazılım ile sürekli evrilen alan bilgisini (domain) birbirine bağlamak için kullanılır. Burada özellikle model yerine domain kelimesini kullanılıyor. Çünkü modelde statik veri daha ön plana çıkıyor hissi var.

DDD Eric Evans'ın 2003 yılında yayınlanan "Domain-Driven Design: Tackling Complexity in the Heart of Software" adlı kitabından doğmuştur

Model Driven Architecture vs Domain Driven Design
Model Driven Architecture ile Domain Driven Design arasındaki fark şudur:
In MDA, we start with database table diagrams or ERDs, and build objects to match.  In DDD, we start with interactions and behaviors, and build models to match.
DDD ve Nesneye Yönelik Tasarım el ele birbirlerine destek olan kavramlardır.

Temel Kavramlar
DDD kodun belli şekilde düzenlenmesini bekler. Açıklaması şöyle.
One of the ways DDD helps teams of developers is by suggesting a specific (yet still subjective) way of organising your code concepts and behaviours. This convention makes it easier to discover things, and therefore easier to maintain the application.

-Domain concepts are encoded as Entities and Aggregates
-Domain behaviour resides in Entities or Domain Services
-Consistency is ensured by the Aggregate Roots
-Persistence concerns are handled by Repositories

This arrangement is not objectively easier to maintain. It is, however, measurably easier to maintain when everyone understands they're operating in a DDD context.
Şeklen şöyle


1. Ubiquitous Language
Müşteri ile konuşulan ortak dil. Açıklaması şöyle.
Ubiquitous Language is the practice for building up a communication language between developers and users. It helps developers and the business share a common language platform that both parties understand to mean the same things. Ubiquitous Language should evolve as the team's understanding of the domain grows.
2 Bounded Context
Bounded Context yazısına taşıdım.

3. Entity
Kendine ait bir kimliği olan nesne. Açıklaması şöyle.
An Entity is an object that can be identified uniquely or by its identifier. An Entity can be identified either by its IDs or a combination of some attributes. An entity is an identity.
4. Value Object
Kendine ait bir kimliği olmayan nesne. Açıklaması şöyle.
A Value Object is an object that contains attributes but has no conceptual identity. It is a descriptor or property which is important in the domain you are modeling.
5. Repository
Nesnelerin saklandığı alan. Açıklaması şöyle.
A Repository mediates between the domain and data mapping using a collection-like interface for accessing domain objects. It is more like a façade to your data store that pretends to be a collection of your domain. A Repository provides a centralized façade, storing data in a database, XML, SOAP, REST, and so on.
Repository sorgu inşa eder. Repository örüntüsüne alternatif olarak direkt Query Object kullanımı (yani sorgunun kendisi) sunuluyor.

Klasik bir Repository nesnesine şuna benzer metodlar bulubur
getById(), deleteById(), getAll(), save(), update(). Repository altta "Entity Framework" veya "JPA" gibi bir ORM kullanabilir.

Nesne çekmek için örnek
CSAgent agent= (CSAgent) EmployeeRepository.getById(agentId);
Order order= OrderRepository.getById(orderId);
6. Aggregate Root veya Aggregates
Aggregates yazısına taşıdım.

Altyapı
Açıklaması şöyle.
...main point is to split the Domain Logic (Business Logic) from the Infrastructure (DB, File System, etc.).
Veri tabanı
Açıklaması şöyle.
These days, you are likely to see reads (queries) handled differently than writes (commands). In a system with a complicated query, the query itself is unlikely to pass through the domain model (which is primarily responsible for maintaining the consistency of writes).
Servisler
Yukarıdaki kavramların bazılarının servis olarak ta anlatıldığı görülebilir.
- Application services.
- Domain services.
- Infrastructure services.
- Factories, Repositories, Specifications
Application Services - Dış Dünyaya Sunulan Servisler
Application Services yazısına taşıdım.

Specifications - İş kuralları
Specifications yazısına taşıdım

Domain Services
Domain Services yazısına taşıdım.

Infrastructure Services - Kendi Kaynaklarımıza Erişmek İçin Servisler
Açıklaması şöyle.
An Infrastructure Service is a service that communicates directly with external resource. For example, accessing file system, registry, SMTP, database, and so forth in the application.
Anti Corruption Layer
Anti Corruption Layer yazısına taşıdım.

Anemic Design Model
Anemic Design Model yazısına taşıdım..


Hiç yorum yok:

Yorum Gönder