Defining interface

I have a datamodel used by several applications, which now I need to use by other developers outside the team. The model must be made incomplete for developers.

I wonder how I best approach this: my current approach is to create a new project that simply copies the original model and includes only the requested properties.

eg

namespace Model { public class Car { private double m_speed; private FuelType m_fuelType; public double Speed { get { return m_speed; } set { m_speed = value; } } public FuelType FuelType { get { return m_fuelType; } set { m_fuelType = value; } } } } 

In my Lite model, I only want to show speed:

 using Model; namespace ModelLite { public class Car { private Model.Car car = new Model.Car(); public double Speed { get { return this.car.Speed; } set { this.car.Speed = value; } } } } 

Since the model is large, this involves a lot of duplication. Maybe there is a better alternative?

thanks

+6
c # architecture
source share
3 answers

Take a look at Martin Fowler's work on Application Facades and Facade Image

+2
source share

There is no solution to this problem. If different developers are only allowed partial access to the fields, you will need to create different channels for different developers.


Although your model seems wrong to me, you can, however, do this:

  • Creating a single feed object that has all the properties, the main object also has
  • Create an attribute like:

  class FeedSecurityAttribute : Attribute { public FeedSecurityAttribute(params string[] rights) {} } 

  • Add annotations to the feed’s properties, indicating who has access to this property, for example [FeedSecurity("piet", "klaas")] string MyProperty { get;set; } [FeedSecurity("piet", "klaas")] string MyProperty { get;set; }
  • Fill your feed object from the business object automatically using some reflection and expression trees, and check if the user has access to this property, otherwise ignore it.
+2
source share

Perhaps you can use several interfaces

 public interface ICarBasic { double Speed { get; set; } } public interface ICar : ICarBasic { FuelType FuelType { get; set; } } 

Or write your entire base object as base classes. Inherit from them to make complete classes using the new assembly. Providing developers with a third-party project, only assembly with base classes can solve your problem.

Assembly 1 (for other developers)

 using Model; namespace ModelLite { public class Car { private Model.Car car = new Model.Car(); public double Speed { get { return this.car.Speed; } set { this.car.Speed = value; } } } } 

Unit 2 (fully functional)

 using ModelLite namespace Model { public class Car : ModelLite.Car { private FuelType m_fuelType; public FuelType FuelType { get { return m_fuelType; } set { m_fuelType = value; } } } } 

Only give assembly 1 to other developers.

0
source share

All Articles