Relative Content

Tag Archive for object-oriented-design

Object behaviour or separate class?

When it comes to OO database access you see two common approaches – the first is to provide a class (say “Customer”) with methods such as Retrieve(), Update(), Delete(), etc. The other is to keep the Customer class fairly lightweight (essentially just properties) and perform the database access elsewhere, e.g. using a repository.

Is this a violation of the Liskov Substitution Principle?

Say we have a list of Task entities, and a ProjectTask sub type. Tasks can be closed at any time, except ProjectTasks which cannot be closed once they have a status of Started. The UI should ensure the option to close a started ProjectTask is never available, but some safeguards are present in the domain:

What can go wrong if the Liskov substitution principle is violated?

I was following this highly voted question on possible violation of Liskov Substitution principle. I know what the Liskov Substitution principle is, but what is still not clear in my mind is what might go wrong if I as a developer do not think about the principle while writing object-oriented code.

Do unit tests sometimes break encapsulation? [duplicate]

This question already has answers here: Should I avoid private methods if I perform TDD? (14 answers) Closed 10 years ago. I very often hear the following: “If you want to test private methods, you’d better put that in another class and expose it.” While sometimes that’s the case and we have a hiding concept […]

Object oriented wrapper around a dll

So, I’m writing a C# managed wrapper around a native dll. The dll contains several hundred functions. In most cases, the first argument to each function is an opaque handle to a type internal to the dll.

DB Object passing between classes singleton, static or other?

So I’m designing a reporting system at work it’s my first project written OOP and I’m stuck on the design choice for the DB class.
Obviously I only want to create one instance of the DB class per-session/user and then pass it to each of the classes that need it. What I don’t know it what’s best practice for implementing this. Currently I have code like the following:-

design a model for a system of dependent variables

I’m dealing with a modeling system (financial) that has dozens of variables. Some of the variables are independent, and function as inputs to the system; most of them are calculated from other variables (independent and calculated) in the system.