모두 함께 대상을 향한 3층 구조를 배워봅시다!오늘은 제가 Entity를 말씀드리자면 가끔 MODEL 실체층이라고도 합니다!
17687 단어 entity
쓸데없는 말은 그만하고 내 실체 디자인을 봐라!
1: #region 2: /// <summary> 3: /// 4: /// </summary> 5: public interface IDataEntity 6: { 7: } 8: /// <summary> 9: /// 10: /// </summary> 11: public interface IEntity 12: { 13: /// <summary> 14: /// , , , set 15: /// </summary> 16: bool IsValid { get; } 17: /// <summary> 18: /// 19: /// </summary> 20: /// <returns></returns> 21: IEnumerable<RuleViolation> GetRuleViolations(); 22: } 23: /// <summary> 24: /// 25: /// </summary> 26: public class RuleViolation 27: { 28: public string ErrorMessage { get; private set; } 29: public string PropertyName { get; private set; } 30: public RuleViolation(string propertyName, string errorMessage) 31: { 32: this.ErrorMessage = errorMessage; 33: this.PropertyName = propertyName; 34: } 35: public RuleViolation(string errorMessage) 36: { 37: this.ErrorMessage = errorMessage; 38: } 39: } 40: public partial class Department : IDataEntity 41: { 42: // 43: #region original field 44: 45: /// <summary> 46: /// 47: /// </summary> 48: public int DeptID { get; set; } 49: 50: /// <summary> 51: /// 52: /// </summary> 53: public string DeptName { get; set; } 54: 55: /// <summary> 56: /// 57: /// </summary> 58: public DateTime CreateDate { get; set; } 59: 60: /// <summary> 61: /// 62: /// </summary> 63: public DateTime UpdateDate { get; set; } 64: 65: /// <summary> 66: /// 67: /// </summary> 68: public string Operator { get; set; } 69: 70: /// <summary> 71: /// ID, ID 0 72: /// </summary> 73: public int ParentID { get; set; } 74: 75: #endregion 76: 77: // 78: #region extensional field 79: #endregion 80: 81: // 82: #region constructed function 83: 84: /// <summary> 85: /// 86: /// </summary> 87: public Department() 88: { 89: 90: } 91: 92: /// <summary> 93: /// 94: /// </summary> 95: /// <param name="_DeptID"></param> 96: public Department(Int32 _DeptID) 97: { 98: this.DeptID = _DeptID; 99: 100: } 101: 102: #endregion 103: 104: // 105: #region function 106: 107: #endregion 108: 109: // 110: #region object overrides 111: 112: #endregion 113: } 114: 115: public partial class Department : IEntity 116: { 117: 118: #region IEntity 119: 120: public bool IsValid 121: { 122: get { return (GetRuleViolations().Count() == 0); } 123: } 124: 125: public IEnumerable<RuleViolation> GetRuleViolations() 126: { 127: if (String.IsNullOrEmpty(this.DeptName)) 128: yield return new RuleViolation(" ", "DeptName"); 129: if (String.IsNullOrEmpty(this.Operator)) 130: yield return new RuleViolation(" ", "Operator"); 131: yield break; 132: } 133: 134: #endregion 135: } 136: 137: #endregion 잘 보셨죠? 우리의 실체는 두 부분으로 구성되어 있습니다. 즉,'실체의 기본 속성'과'실체의 검증 메커니즘'입니다. 하하
느끼러 가자!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA 연관 관계 매핑1_일대일 단방향 매핑하기Entity들은 대부분 다른 Entity와 연관 관계를 맺고 있다. JPA에서는 Entity에 연관 관계를 매핑해두고 필요할 때 해당 Entity와 연관된 Entity를 사용해 조금 더 객체지향적인 프로그래밍(OOP...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.