DDD Repositories pattern with NHibernate [closed] - orm

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Im confused. This is a blog entry of Ayende Rahien Repository is the new singleton.
I believe that a repository should only do CRUD operations and not addtional queries otherwise youll end up with methods like these on your repository.
FindCustomer(id)
FindCustomerWithAddresses(id)
FindCustomerWith..
So my question is, where(in what layer) would one do the queries to retrieve entities?

It's possible to write repository which have default CRUD operations. For example:
public interface IRepository<TEntity>
{
TEntity FindByIdentity(object identity);
TEntity FindBy(Expression<Func<TEntity, bool>> specification);
IList<TEntity> FindAll();
IList<TEntity> FindAllBy(Expression<Func<TEntity, bool>> specification);
TEntity Save(TEntity saveable);
void Delete(TEntity deletable);
}
Expression> is basically Specification and queries can be encapsulate that way. If we have that kind of Repository then we don't need to write many specific repositories.
Alternative path is create Query object. We could add interface of that query to Core/Busines Logic layer and implementation to Services/Data layer. That way we have nicely named queries like AllPreferredCustomersQuery. It's quite similar to specifications, but specifications don't use infrastructure and therefore we may add it to Core/Business Logic layer. Query objects are more configurable (e.g. possible to add limits, fetching strategies, joins etc.)

Related

How to protect a base class from causing errors in its subclasses? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
One of the disadvantages of inheritance is that the superclass and its subclasses are very tightly coupled. A lot of resources (e.g. SO) say to compensate for this by being 'cautious' when writing a class that might be subclassed.
Are there any guidelines about what precautions you should take, or testing processes to go through to make sure your base class is safe? Or do you just have to try to predict all potential subclass behavior?
Do as little as required in the parent classes. If you must do more complex operations then separate them into logical pieces, putting each piece in a different method so that children can override them as appropriate.

Interfaces - still trying to understand them [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Would I be correct in thinking that an interface has 3 main benefits.
A blueprint to what must be created (I have also heard others refer to it as a contract).
Polymorphism.
Unlike inheritance (which IMO has many similarities) you can have many interfaces
Are there any other plus or minus points and does anyone not agree with my 3 points?
The "blueprint" metaphor works better for classes than for interfaces, but the "contract" metaphor is pretty accurate. An interface specifies what other classes can expect in terms of public methods, without saying anything about the underlying implementation. Where inheritance between classes tends to consist of is-a relationships, interfaces can be thought of as works-as-a relationships, though I don't think the latter term is in common use.
I would add that the use of interfaces goes some way to creating self-documenting code. For example, the interfaces that your class implements describes the functionality the class supports. So, you end up with code that looks like:
if (someClass is ISearchable)
{
someClass.Search();
}
Two objects with the same Interface do not need to be otherwise related.
So you could have
- Flower
- Truck
- Dinosaur
all having the same interface
- IColor
even though they are completely different objects.

The use of design patterns in R [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
The use of design patterns in programming is wide spread across many programming languages. A number of examples are the factory, or singleton design pattern. Many of these patterns use object orientation to create abstraction and encapsulation in the code, they aim at make code re-usable and structured. Many of these design patterns could also be used in R, maybe by using the proto library, or standard R object orientation?
My questions are:
What base code (S3, S4) / packages (proto, R.oo) can I use to reproduce design patterns as for example mentioned in the book by Gamma et al?
Are there examples of design patterns implemented in R, both in base R, or in packages?
Some examples of design patterns:
The system.time() function seems to behave much like a decorator pattern. However, almost exclusively decorators are mentioned in the context of object oriented programming. But still, it has the feel of a decorator, it extends (or decorates) an existing piece of code (in OOP always an object) with additional functionality without any need to change the piece of code. Here system.time() is shown in action:
system.time(bla <- Sys.sleep(1000))
#jverzani posted an example of singleton pattern on github.
An example of a Strategy Design Pattern is the apply family of functions. The functionality of looping over the given object is generic, the function that is applied (the strategy) is chosen when the user supplies the function.

When should I use a nested class? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I have a class that I writes iCal events, and it contains nested classes that are public. The class are bascially complex types for components in the iCal such as events, alarms, etc, and it made sense to make them public nested classes that were used by the rest of the program.
I have read that having public nested classes is a sign of bad programming is. Why is it bad and when is it appropriate nested classes?
This is all IMHO but comes from about 15 years of analysing other people's creations:
It is appropriate if the nested classes are private and are not exposed by the public interface of the containing class.
For example a linked list class would have a linked list node class nested inside it which is specific to the implementation internals but will not be exposed to the consumer of the linked list class.
Otherwise, I would not bother as it just adds unnecessary complexity.
For the sake of your example, I'd change all your classes to normal ones if they are exposed by the iCal event class.

Is static method violate the OOP? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I think it is not necessary for me to explain what is the good thing about OOP. But I would like to know discuss is the static method violate the OOP design? or a more OOP way to do is making a singleton to do such static method?
I would like to know what harm is done by static methods and what purpose is served by adhering to object oriented purity.
This question and its answer makes as much sense as any other argument about object-oriented purity and where a particular language falls on the continuum.
C# and Java both support the notion of methods and attributes associated with classes rather than a specific instance.
The benefit or harm of singletons in design have been explored in detail elsewhere.
Static methods wouldn't exist if they were considered to be bad practice in the OOP paradigm. Static methods are absolutely necessary at times, if you know how to use them. If you have a method that does not make use of, or change, any member of a class object, then it is static by nature.