Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Semi-Noob, Needs Some Help With Architecture Question
Post Body

Hey All,

I'm working on an API wrapper (for Snipe-IT) and I've run into delema that I'm not sure how to approach. I'm semi-new to C# and this is the largest project I've tried my hand at.

Each endpoint of the API returns a different type of object (Asset, Model, Location, ect). To model this I started with a base class and interface that covers all the shared properties (name, id, updated at, ect). I then extended this class for each specific type of object each endpoint returns.

To interact with these endpoints I have a single "manager" class. All CRUD operations pass through an instance of this class. Many of the methods return an object from an endpoint. To avoid making duplicate managers for each endpoint, I have methods in the manager return the interface shared by all end point objects.

However, this means the client has to cast everything it receives to the correct concrete class. Due to how this will be consumed it means tons of casting and null checking. It feels super convoluted and wrong to me.

Every time the clients gets an object it ends up like this:

Asset asset = snipe.AssetManager.Get("Loaner1") as Asset;

Client Code Example

The obvious solution would be to make a manager class for each endpoint that returns the concrete object for that specific endpoint. However, that means duplicating the CRUD logic on every manager class, which also feels wrong.

To illustrate: Line 66

I just can't see the correct way to return the concrete object without duplicating the code with a unique manager for each endpoint.

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
15,999
Link Karma
7,214
Comment Karma
7,935
Profile updated: 5 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
7 years ago