10

It makes perfect sense to define such generic interface as long as there is a generic consumer that can do some useful work with any of the implementations. And I suppose there is in this case. If I were to guess, I'd say the tutorial did not include generics just because that is a feature that might not be familiar to the audience that the tutorial was ...


5

It seems not a good idea to hard code the different constants. I would inject them through the constructor (I am using properties instead of Get-methods): public sealed class Publisher : interfaces { public void Publisher (string userType, string dataType, Timespan interval, string url) { UserType = userType; DataType = dataType; ...


5

Yes, but... In the current picture you painted, where all the services are structurally exactly the same, you can indeed use the generic base interface. Your code will work exactly as you expect it to. However, in reality what starts off as an similar structure often ends up diverging, e.g. CustomerService.GetUnderageCustomers() making no sense to be ...


4

This looks like a good opportunity for a generic interface. E.g., interface IDataTimeType<T> where T : IDataType { T RootData { get; } } Then, your time types can be implemented with generics: class Retro<T> : IDataTimeType<T> { Retro(T rootData) { RootData = rootData; } T RootData { get; } } And instantiated ...


3

Incidentally, kudos to you for using the Non-Virtual Interface idiom! (For readers who don't know what it is, see here and here.) To a first approximation, I would say that multiple inheritance is usually a bad design choice, so it probably is bad in this case as well. Looking a bit closer, I don't see the point of ModelABC in this architecture. You have ...


3

To get part of the code review out of the way, and possibly a copy paste error on your part, but the I prefix is reserved for interfaces, not classes. Therefore the last code snippet should be rewritten as: public class CustomerService : IService<Customer> { public async Task<IEnumerable<Customer>> ListAsync() { var entities ...


2

As I said in my comment below your question, java already covers your need of defining custom validators for your data before saving them in the database. The package coupled with the spring framework is the javax.validation package, so taking for example your custom validator code: public class UsernameValidator implements IUserAttributesValidator { ...


2

Let me clarify something fist It gives the caller the ability to use the preferred implementation class. Even if we return interface from method, that doesn't mean that that caller can choose implementation.' So if the caller of op wanted to use a LinkedList they could through simple casting. If you mean something like (LinkedList<Integer>) op(nums)...


1

Very good code, nicely done. As for your questions: For example as the SensorMonitor how can it know the details of currently operating sensors, and what sensors are in the monitoring process? It does not. You have modeled a clear association direction, which is: the sensor knows its listener, the listener does not know the sensor. If you need such an ...


1

The problem here is that the interface IAnimal is not what those apis return. You want to return that interface from your function, but those APIs should have their own interface representing the response data. interface DogApiResponse { message: string status: string } interface FoxApiResponse { image: string } interface Animal { status: string ...


1

It depends on the actual class requirements along with the overall code factors. For instance, Do you think that Client class can be extended in the future? (not by inheritance surely since it's sealed). How often this class is going to be called? How simple you need to simplify the initiation of this class? (as a way to automate handling of its ...


1

Trying to not promote low-level transaction implementation in initial design, IDbContext is the place for db-transactions. public interface IDbContext { void Commit(); void Rollback(); } Using “Generics” to implement “Unit Of Work” public interface IUnitOfWork<T> where T: IDbContext { T DbContext { get; } } Now the async ...


1

@Flater, @slepic, and @Hayden answers have almost cover common case scenarios on when and where to use a generic (or generalized) interface to reuse it. As there are many real world cases applying the same concept. For instance, in .NET, IEnumerable interface is implemented in most .NET collections and arrays. All of which adds the ability to have one ...


1

Ignoring the possibility of implementing this with tools provided by Spring framework... what you have there is quite close to being a composite design pattern so it is a well known and accepted design. What you would need to change to achieve that is to have the both individual validators and the composite validator implement the exact same interface. It ...


1

package hotel; import java.time.LocalDate; import java.util.*; public class Hotel implements HotelManager { private HashMap<Integer, Reservation> reservations; private int numberOfRooms; public Hotel () { reservations = new HashMap<>(); numberOfRooms = 0; } @Override public void setNumberOfRooms (int ...


Only top voted, non community-wiki answers of a minimum length are eligible