I'm contemplating two different class designs for handling a situation where some repositories are read-only while others are read-write. (I don't foresee any need for a write-only repository.)
Class Design 1 -- provide all functionality in a base class, then expose applicable functionality publicly in sub classes
public abstract class RepositoryBase
{
protected virtual void SelectBase() { // implementation... }
protected virtual void InsertBase() { // implementation... }
protected virtual void UpdateBase() { // implementation... }
protected virtual void DeleteBase() { // implementation... }
}
public class ReadOnlyRepository : RepositoryBase
{
public void Select() { SelectBase(); }
}
public class ReadWriteRepository : RepositoryBase
{
public void Select() { SelectBase(); }
public void Insert() { InsertBase(); }
public void Update() { UpdateBase(); }
public void Delete() { DeleteBase(); }
}
Class Design 2 - read-write class inherits from read-only class
public class ReadOnlyRepository
{
public void Select() { // implementation... }
}
public class ReadWriteRepository : ReadOnlyRepository
{
public void Insert() { // implementation... }
public void Update() { // implementation... }
public void Delete() { // implementation... }
}
Is one of these designs clearly stronger than the other? If so, which one and why?
P.S. If this sounds like a homework question, it's not, but feel free to use it as one if you want :)
Yes, it's a bit odd that you can get a loud consensus that K&R is a great C book, and also a loud consensus that C99 is the correct/current/best version of C.
Compared to C, C++ has significantly more libraries and functions to use. If you're working with complex software, C++ is a better fit because you have more libraries to rely on. Thinking practically, having knowledge of C++ is often a requirement for a variety of programming roles.
Ease of development – Python has fewer keywords and more free English language syntax whereas C is more difficult to write. Hence, if you want an easy development process go for Python. Performance – Python is slower than C as it takes significant CPU time for interpretation. So, speed-wise C is a better option.
Answers: Actually, both are difficult and both are easy. C++ is built upon C and thus supports all features of C and also, it has object-oriented programming features. When it comes to learning, size-wise C is smaller with few concepts to learn while C++ is vast. Hence we can say C is easier than C++.
How about a third option, closely related to the first, but using interfaces instead:
public interface IReadRepository {
public void Select();
}
public interface IWriteRepository {
public void Insert();
public void Update();
public void Delete();
}
// Optional
public interface IRepository : IReadRepository, IWriteRepository {
}
public class Repository : IRepository {
// Implementation
}
This way the implementation is (or can be) all in one place, and the distinction is made only by which interface you are looking at.
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