locked
Help for Business Entities RRS feed

  • Question

  • User-574293449 posted

    Hi all,

      I am new to architecture and i am am interested in it. Now i have the responsibility to architect one application and i planned to create SOA architect. I read more arcticles and Application Architectural Guide. Now i have some doubts when i discussed with my friend regarding Business Entity creation.

    Take an example, i am creating an application to enter daily expence. I have User, ExpenceType, Expence Entry. Here i can create 3 business enity for User, EnpenceType and ExpenceEntry. Each entity class i have UserID, ExpenceTypeID, EnpenseEntryID etc. Also ExpenseEntry class have UserID and EnpenceTypeID.

    My friend told that use single class for all common objects like ID and inherit in other entities. This is best practice and also use singleton pattern. So i am confused and please help to find the answers for the following questions...

    1. How i use common class and ID in those base classs using inheritance. Is this better?

    2. How i achive singleton pattern using this example?

    3. I have UserID and ExpenseTypeId in ExpenceEntry. How i treat this? I mean my way is good like create these IDs in EnpenseEntry entity or any other methos to access from those particluar Entities? Which one is better appraoch?

     

     

     

    Monday, August 8, 2011 12:05 PM

Answers

  • User-1322853079 posted

    In first case when you declare ID as propertiey in the base class.., you need not override it in child class., you can directly use as its member.

    As discussed above maintiain all the common prioperties in the base class and extra properties (which are specific to an entity) maintain in the child class entity as you did for ExpenseEntry (the second case)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 10:13 PM

All replies

  • User-1322853079 posted

    1. How i use common class and ID in those base classs using inheritance. Is this better?

     Ans:  Yes , It is better to use a base class for Common properties.

    2. How i achive singleton pattern using this example?

         Singleton pattern is used when multilple threads accessing the common component..,just like DAL instance..., I mean when instance is costly to create again and again..we go for singleton pattern

         In designing business Entity there is no need to use Singleton pattern..

    3. I have UserID and ExpenseTypeId in ExpenceEntry. How i treat this? I mean my way is good like create these IDs in EnpenseEntry entity or any other methos to access from those particluar Entities? Which one is better appraoch?

      Yes.., Create public properties for these TypeId and ExpenseTypeId..

     

     

    Tuesday, August 9, 2011 8:31 AM
  • User-574293449 posted

    hi friends,

      Thanks for your answer. So please review and confirm my approach is right..

    1. So base class for common properties and inherit in other entities. So my following code is right?

    public class Master
    {
      public int ID
       {
        get;
        set;
       }
    }
    
    public class User : Master
    {
      public int UserID
       {
        get
        {
         return this.ID;
        }
        set
        {
         this.ID = value;
        }
       }
    }

    Is this correct?

    3. So all foriegn key ID needs in the entity

    public class ExpenseEntry
    {
      public int UserID
       {
         get;
         set;
       }
      public int ExpenseTypeID
      { 
        get;
        set;
       }
    }

    Is this correct? or this foriegn key ids are also inherit from base class like point 1 ?

    Tuesday, August 9, 2011 11:17 AM
  • User-1322853079 posted

    In first case when you declare ID as propertiey in the base class.., you need not override it in child class., you can directly use as its member.

    As discussed above maintiain all the common prioperties in the base class and extra properties (which are specific to an entity) maintain in the child class entity as you did for ExpenseEntry (the second case)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 10:13 PM
  • User-574293449 posted

    K thanks friedn i got it. Can you guid one more scenario. Actually application contains Web, Windows and also windows services. So all these access Service Layer (WCF) to access the business logic and continue to DAL. Windows Serviecs save data in to the database from xml file continously when xml created on folder. So all services works with timer. In  this scenario Singleton pettern is good approach or not? If yes, where i do that in Serice layer / Business Component  / DAL?

    Wednesday, August 10, 2011 1:29 AM
  • User-1322853079 posted

    Lets say you are using a common DAL instance in our business component.., you can intialise it in the base classs of the Business Layer (in contstructor)

    Eg:  public static DAL dbInstance;

    if(dbInstance == null)

    {

    dbInstance = CreateDBInstance();

    }

    If you feel the dbInstance is costly to create agaain and again...because of method CreateDBInstance() method..,make it static as above and create instance when it is null..

    So in our application.., use singleton patterrn as required...,mainly it is applicable for the components we use like DAL

    Also check this reference

    http://himabinduvejella.blogspot.com/2011/02/what-singleton-design-pattern-how-did.html

     

     

    Wednesday, August 10, 2011 3:41 AM
  • User-574293449 posted

    thnks friend..

    Wednesday, August 10, 2011 10:11 AM