Click here to Skip to main content
15,886,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public  class Customer 
    {
 	Int32 CustomerID { get; set; }
        string Customer_Name { get; set; }
        string Customer_Add1 { get; set; }
	
	public   void save( )
        {

            _CustomerRepository.save(this);

        }

	 public   void Delete()
        {

            _CustomerRepository.Delete(this);

        }

    }


What I have tried:

what i was doing is by having two different class: one for the modal and other for the methods which have reference to the model.

will it violate design principles?.How we do in enterprise projects?
Posted
Updated 19-Apr-17 1:40am
Comments
Nick_3141592654 19-Apr-17 7:40am    
I would not, as a rule, recommend separating your properties and methods. Classes typically encapsulate all such related items and maintenance/code-sharing may become harder if you need to dive into separate classes to see how the whole thing works together.

It sounds as though you may be gravitating towards a Model-View-Controller (MVC) design pattern, which certainly does have value.

I use a such a pattern (MVC-inspired) in Android to achieve a clean separation of UI from business logic, and this uses a class to hold all configurable settings (as properties) along with some helper methods to deal with things like shared-preferences. (One such 'settings' class for each category of business logic, not one global class, which would be horrible.)

I would advise you to do some reading about MVC before launching into some new paradigm of your own.
Mahi8089 19-Apr-17 7:52am    
hello nick..
am into asp.net webforms and not MVC.
Am trying to develop loosely coupled classes using Interfaces and DI.
Nick_3141592654 19-Apr-17 8:01am    
Hi Mahi, just to clarify MVC is a design "pattern" - it defines a structural model for software structure - that is applicable to very many languages. Wherever you are using OO principles you could be using MVC. The whole point of MVC is that it provides a de-coupling between classes that may otherwise get entangled. It's up to you but I do think it is very relevant to your question.
Mahi8089 19-Apr-17 8:10am    
hi nick, so is to get the modal separated from methods and reference in difference layers?
i mean class.save() or class.save(objcust), which will be a better choice for layered architecture.
CHill60 19-Apr-17 7:42am    
A class without methods and a class without properties ... hm ... I'm not sure what "design principle" that would violate, but it does not make any sense at all.
In your sample code you have properties and methods in the same class.
However it sounds as if you are trying to implement the Repository Pattern - which would be used in Enterprise level projects - The Repository Pattern[^]

1 solution

You need to create two different classes inorder to avoid tight coupling of data
 
Share this answer
 
Comments
Mahi8089 19-Apr-17 7:55am    
that means referencing the modal class in UI layer, BL Layer and DL layer..?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900