Tag Info

New answers tagged

4

The purpose of the PIMPL idiom is to provide a more low-level separation between the interface and the implementation* so that you can alter the implementation without affecting the interface. In particular, this means the library can retain binary compatibility, allowing users to link to a new version of the library without recompiling their executables. ...


2

Use a simple Adapter to bridge the connection between the two systems. This is a basic Enterprise Integration pattern and it specifically addresses your concern by kind of mixing your two approaches. Think of the link between Sharepoint and the other application as a Message Channel (or "routing" as you've put it). The adapter can sit at any end of the ...


0

The reference to the object-relational impedance mismatch is an interesting read. However when we look at it more carefully, it is basically complaining why a square peg is not fitting a round hole. That is what a really good ORM product resolves. Unfortunately having been part of two separate ORM's design and development, I can say that many ORM's bring ...


3

You ask why, as if the whether is decided. Lets consider your supposition: Why is inheritance generally viewed as a bad thing by OOP proponents I disagree with the premise of the question. Inheritance isn't generally viewed as bad, it is viewed as misused and overused. GoF Design Patterns says no such thing about it being bad. Let's see what GoF ...


1

...my friend who thinks it is a valid blanket statement but is it not more sensible to... Yes, it is always more sensible (time permitting) to understand why things are the way they are rather than following some mantra blindly. real reason why inheritance exists is not just for behaviour reuse but for the case where a hierarchy of classes ...


0

Dittos on all the comments, something is really wrong. That said, maybe a stack will work... You must expose something to the client because only the client can know its own scope context. public class MyClassA { public Stack<Student> stackedStudents = new Stack<Student>(); // it's an all-girl college. } // meanwhile, in some other class ...


2

How about using interfaces? public interface IImmutableWorld { // only get methods } public interface IMutableWorld : IImmutableWorld { // add set methods } public class World : IMutableWorld { // implementation for both get and set methods. } You don't need to directly talk with World class, you talk with the interfaces. For example, ...


-2

You could use weak references for your purpose. See http://msdn.microsoft.com/en-us/library/ms404247(v=vs.110).aspx for more details. Note that this will not result in x being set to 0 automatically. However, when asked for the reference, you can verify that the strong reference to your weak reference still exists and then hand it out, or null if not. If ...


6

Basically a Subway network is a collection of line, a line is a collection of stations and a station a collection of intersections (1 or more other stations connected) . You could have your Subway network represented by a basic hashMap with all your lines. Your stations could be modeled as a collection of intersection/sequences Subway network - Lines ...


2

1. Is the problem identified above valid or do I lack understanding of the builder pattern? Should we not reuse builder objects to created multiple instances? It can be, depending on your situation. Here you've identified that you have mandatory fields that are unique, therefore making them parameters to your build method allows you to reuse the same ...


19

Let's ignore for a second that the method in question is __construct and call it frobnicate. Now suppose you have an object api implementing IHttpApi, and an object config implementing IHttpConfig. Clearly, this code fits the interface: $api->frobnicate($config) But let's suppose we upcast api to IApi, for example passing it to function ...


14

Yes, this follows directly from the Liskov Substitution Principle (LSP). When you override a method, the return type can become more specific, while types of arguments must stay the same or can become more general. This is more obvious with methods other than __construct. Consider: class Vehicle {} class Car extends Vehicle {} class Motorcycle extends ...


7

The text you quoted has good advice, although I will replace “data structures” by “records”, assuming that something like structs is meant. Records are just dumb aggregations of data. While they might be mutable (and thus stateful in a functional-programming mindset), they don't have any internal state, no invariants that have to be protected. It is ...


3

The fact that handleTrade() and updateRun() always happen together (and the second method is actually on the visitor and calls several other methods on the data object) smells of temporal coupling. This means that you must call methods in a specific order, and I would guess that calling methods out of order will break something at worst, or fail to provide a ...


0

From my point of view a class should contain "values for state (member variables) and implementations of behavior (member functions, methods)". The "unfortunate hybrid data structures" emerges if you make class state member-variables (or their getters/setters) public that should not be public. So I see not need to have seperate classes for data data ...


0

I seem to be taking verbs, 'download', 'parse', and then converting them to nouns in order to make them appear as valid classes. I feel very lost and confused. Again, the purpose for me is to learn how to properly make and design OO software. I'm not looking just to get the program to work. The biggest challenge when starting out with object ...


1

I believe the inheritance approach taken here in your question is to only guarantee that the object creation happens in a whole by appropriately setting the mandatory attributes of the class, if the proper object creation is the sole purpose then i would suggest object Builder patterns instead of going with the inheritance approach.


9

While mildly distasteful, this sort of thing isn't the worst thing in the world. It doesn't explictly violate any OO principles. My main complaint is that with just the code above, not all right angles are RightAngles, though using value semantics would solve that. Personally, I would work to make the class immutable and then simply have a static readonly ...


-1

Maybe CQRS is worth looking at for you. http://martinfowler.com/bliki/CQRS.html More specifically: Interacting with the command-model naturally falls into commands or events, which meshes well with Event Sourcing. So in this pattern, you send updates to the domain model using commands sent via. events.


0

If I understand you correctly, you have two kinds of state-objects: The @Entity which is used in the persistence-context (Hibernate) The "viewmodel", which deals with user input and as you describe: »which uses MyOjectService« So your dataflow is from the user to the viewmodel and from the viewmodel to the Entity - we could neglect the persitence for ...


0

I've built several DDD models, persistence was handled by NHibernate. We went with a repository pattern in our early projects and built all of our queries into our repositories. This is a great idea in theory but what we learnt in practice is that you end up writing a lot of boiler place when implementing the repositories and also they were practically ...


0

One approach is to separate your query model (the model that displays data) from your command model (the model that changes data). This is referred to as CQS, Command Query Separation. From an article describing CQS The concept of applying CQS at an architectural level says, our Domain and transactional operations will use the Repositories, but for ...


0

You should always follow OO design principles (e.g., modularity, information hiding, high cohesion, etc.). Design patterns are a relatively refined niche of OO design principles, especially if you consider the KISS principle. Patterns are solutions to common design problems. These problems come from one of two places (or a mix of both): the problem space ...


0

I'll offer some general problem-solving advice first then use it on your problem so you can see how someone with more experience might approach this. Problem Domain As you may have read elsewhere, your design and your code are a representation of your understanding of the problem you're trying to solve. So, before you start coding and before you start ...


4

I will buck the trend a little, because the answer is more subtle than other answers are letting on. Every class you write should not employ a design pattern, but most non-trivial programs you write likely should. A non-trivial program without any design patterns indicates: Your program is so unique that no portion of it is similar to common problems ...


4

Broken question. Let me give you a novel definition of design pattern that would undo a lot of damage released by GoF: a design pattern is a good coding practice. That's it. Any reasonably complex module will have several design patterns in it. Any time you cache it's probably a flyweight pattern but I'm not going to revoke your programming degree if you ...


29

No. This is what the Gang of Four (who originally popularized design patterns) had to say about it in their book: "No discussion of how to use design patterns would be complete without a few words on how not to use them. Design patterns should not be applied indiscriminately. Often they achieve flexibility and variability by introducing ...


9

Design patterns have two advantages They are easy to describe to other developers, because people generally agree on what the patterns are They tend to have been beaten on pretty thoughtfully by our predecessors, so their strengths and weaknesses are well understood. The goals of every program should be It works. It has to do whatever the end goal is, ...


26

if I am writing more complex code, should there always be some design pattern that I am following? No. Design patterns are just that: patterns in relationships between objects. In other words, relationships that are used and reused often enough that someone said "Hey, we seem to be doing this a lot, let's give it a name." The list of design patterns ...


125

should there always be some design pattern that I am following? Dear God NO! I mean, you can go ahead and say that any random code is following some random XYZ pattern, but that's no more useful than me claiming to be king of my computer chair. Nobody else really knows what that means and even those that do won't exactly respect my claim. Design ...


-3

Refactoring with DougM approach to handle it with a Java String had the best result posible as only getters and setters where changed, with little amount of efford.


4

WordPressParser asks WordPressClient to get blog-posts... Is this really what a parser should do? Asking to get blog posts is not "parsing" by any definition of the term. It's like scissors sending you an invitation to come over to your local barber shop. Now, scissors surely have their business in making it happen, but triggering this entire chain of ...


0

It really depends on where you're going. The reason to go with classes over method is classes are the starting point for some powerful OO patterns that you can take advantage of. Take classes, add inheritance and polymorphism and now you can start taking advantage of contract based programming (i.e. Interfaces). This is very important. It allows you to ...


-1

How would you do it? I'm not familiar with Python, but that sort of construct to build a composite or decorator pattern is something I've done a few times (albeit in C# and C++). It makes for a very nice interface and very usable code. As long as you consider the BinaryExpression and similar composite/decorators part of the core library/API that ...


0

There are several questions that need to be asked to make the decision you want to make. Firstly, does the private class encapsulate data? If so, why is it static? Alternatively, if all that the class does is provide some methods, then it can probably stay static. Secondly, the size of class A doesn't really matter, provided it follows the following ...



Top 50 recent answers are included