I have a datamodel used by multiple application that I now needs to be used by other developers outside the team. The model should only be made partialy available to the developers.
I wonder how I best approach this: my current approach is to create a new project that just copies the orginal model and only include the requested properties.
for example
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 expose the 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 big this involves in a lot of duplication. Maybe there is a better alternative?
Thanks
An interface is declared by using the interface keyword. It provides total abstraction; means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. A class that implements an interface must implement all the methods declared in the interface.
An interface in the Java programming language is an abstract type that is used to describe a behavior that classes must implement. They are similar to protocols.
1. The definition of interface is a surface that forms a common boundary between two things or a point of interaction between two components or systems. An example of interface is someone using the controls on a washing machine to tell the machine how to function. noun.
You use an interface to define a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. Interfaces are useful for the following: Capturing similarities among unrelated classes without artificially forcing a class relationship.
Take a look at the work by Martin Fowler on Application Facades and the Facade Pattern
There is no solution to this problem. If different devs are only allowed to have partial access to fields, you will need to create different feeds for different devs.
Although your model just seems wrong to me, you might however accomplish this by:
class FeedSecurityAttribute : Attribute
{
public FeedSecurityAttribute(params string[] rights) {}
}
[FeedSecurity("piet", "klaas")] string MyProperty { get;set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With