Skip to main content

Practice ยท 3 of 4

DTO: Hide the Internals

CHALLENGE
Difficulty: intermediate+25 XP

Employee (domain) carries Salary โ€” which must never cross the public boundary. Implement: - Solution.ToPublic(Employee e) returning a PublicDto with only safe fields (Name, Dept) โ€” the DTO type must not even declare a Salary member. - Solution.TeamReport(Employee[] staff) returning public rows in input order โ€” the report is built from boundary types, not domain ones. ``csharp public static class Solution { public sealed class Employee { public string Name = ""; public string Dept = ""; public decimal Salary; } public sealed class PublicDto { public string Name = ""; public string Dept = ""; } public static PublicDto ToPublic(Employee e); public static PublicDto[] TeamReport(Employee[] staff); public static bool DtoHasSalaryMember(); // reflection probe used by the tests } ``

Back to lesson: Practice: Architecture Practice: Seams, Batches, Boundaries