Download presentation
Presentation is loading. Please wait.
1
Single Value Objects as C# structs
Domain-Driven Design bottom-up Corniel Nobel, , A’dam
2
About me Corniel Nobel Energetic, optimistic, creative, out of the box thinking, experienced software engineer Exact (2014-current) Senior software engineer Qowaiv community (2013-current) Founding member TJIP ( ) OGD ICT-diensten ( ) IT-Professional 2B Insite ( ) Software engineer
3
Program Structs in C# DDD in short Single Value Objects Design choices
Qowaiv Demo Questions Program 3 - Single Value Objects as C# structs
4
Structs in C# 4 - Single Value Objects as C# structs
5
Reference Types & Value Types
Pointer to data elsewhere in memory Mutable by default Inheritable by default Examples Object String* Type[] Value Type Stores own data (or point to data) Immutable by design* Sealed by design Examples Single, Double, Decimal Byte, SByte Int16, Int32, Int64 UInt16, UInt32, UInt64 Boolean, Char, DateTime, Guid 5 - Single Value Objects as C# structs
6
DDD in short 6 - Single Value Objects as C# structs
7
DDD in short Domain Subject area of the software Model Repositories
Aggregate roots Entities (Single) Value Objects Ubiquitous Language Language structured around the domain (Bounded) Context 7 - Single Value Objects as C# structs
8
Single Value Objects 8 - Single Value Objects as C# structs
9
Single Value Objects in DDD
Subset underlying primitive type Self-descriptive Immutable Equal by value 9 - Single Value Objects as C# structs
10
Example SVO’s Percentage Date Week date Year Month Country Currency
Stream size UUID Seed SQL Timestamp Initials Gender House number address Postal Code BMI IBAN BIC BSN License plate Elo 10 - Single Value Objects as C# structs
11
Example Stream Size var size = StreamSize.FromMegaBytes(12.4); var size = StreamSize.Parse("13 kb"); StreamSize size = 1400; Console.WriteLine("The file was {0:0.0 F}.", size); // The file was 13.0 Kilobyte 11 - Single Value Objects as C# structs
12
Example Postal Code var code = PostalCode.Parse("1234ab"); if (code.IsValid(Country.BE)){ /* ... */ } Console.WriteLine(“Your postal code: {0:NL}", code); // Your postal code: 1234 AB 12 - Single Value Objects as C# structs
13
Example IBAN var iban = IBAN.Parse("nl20ingb "); Console.WriteLine(“Your IBAN: {0:F}", iban); // Your IBAN: NL20 INGB 13 - Single Value Objects as C# structs
14
Design Choises 14 - Single Value Objects as C# structs
15
Creation & conversion No (public) constructor
Parse(string) & TryParse(string) Create(underlying) & TryCreate(underlying) TypeConverter Casting String (explicit) Underlying type (implicit and/or explicit) 15 - Single Value Objects as C# structs
16
Validation Potential valid False positive/negative IsValid()
Context independent IsValid(context) 16 - Single Value Objects as C# structs
17
Serialization RunTime Serializable Attribute System.Iserializable
Ctor(SerializationInfo, StreamingContext) XML System.Xml.IXmlSerializable JSON void FromJson() void FromJson(String;Int64;Double;DateTime) Object ToJson() 17 - Single Value Objects as C# structs
18
Formatting & debugging
IFormattable ToString() ToString(string) ToString(IFormatProvider) ToString(string, IFormatProvider) [DebuggerDisplay("{DebuggerDisplay }")] private string DebuggerDisplay { get; } Unified internal string representation* 18 - Single Value Objects as C# structs
19
Qowaiv 19 - Single Value Objects as C# structs
20
Qowaiv community Open Source .NET library MIT licence Code generator
GitHub github.com/Corniel/qowaiv NuGet packages Qowaiv Qowaiv.Web Qowaiv.Json.Newtonsoft 20 - Single Value Objects as C# structs
21
21 - Single Value Objects as C# structs
22
Questions? 22 - Single Value Objects as C# structs
23
Disclaimer This document contains certain statements and expectations that are forward looking, and which are based on information and plans that are currently available. By their nature, such forward-looking statements and expectations generate risk and uncertainty because they concern factors and events in the future and depend on circumstances that may not occur. Unforeseen factors that could influence the statements and expectations may, for instance, be changes in expenditures by companies in the markets we operate in; economic, political and foreign exchange fluctuations; possible statutory changes; changes in salary levels of employees; or future takeovers and divestitures. Exact can therefore not guarantee the accuracy and completeness of such statements and expectations, nor that such statements and expectations will be realized. Actual results may differ materially. Exact refuses to accept any obligation to update statements made in this document.
24
Exact. Cloud business software.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.