Tag Info

Hot answers tagged

124

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 ...


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 ...


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 ...


10

I would approach this problem as I would approach any localization issue: ResourceBundle. I use a class called I18n that has a static method called getMessage that takes a key and optionally a list of arguments. The key gets looked up in a ResourceBundle configured to use the default Locale or whatever you prefer (specifics here aren't important, so long ...


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, ...


5

There is a third, hybrid alternative, which is to put each global into its own module and write functions to support it. This gives you the OOP-y benefit of all code relating to the variable being isolated in one place and much easier to re-use elsewhere if needed. Putting the support functions in the header so they can be inlined instead of forcing calls ...


5

First of all, a simplification: all real numbers are a subset of complex numbers, so just do everything with complex numbers. Secondly, why isn't Root supported by ComplexNumber? If you're supporting complex numbers, then you can take the root of any number, including negative or complex ones. It all just becomes vector multiplication. So if it's all ...


5

Repeat after me - Patterns are not always the answer Phew. Now that we've gotten that out of the way, lets move on. First off, anytime you're extending 3rd party code that doesn't make any guarantees to lifespan or function declarations, you're asking for a nightmare when updating that 3rd party code. A method could change it's parameters, or the class may ...


5

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 ...


4

You're doing this backwards. Forget about the design patterns for awhile. Just build your calculator program. Build it from scratch, and just design it however it is intuitive to you. Think about it for a few minutes, come up with a few ideas, then roll with it, start to finish. While you are trying to implement your calculator, you might not design it ...


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 ...


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 ...


4

You are confused. Synchronizing two different instances of similar data requires knowing which version is correct if there is a discrepancy. If an email message is on one side and not on the other, how do you know whether you should replay a "delete" on the one side, or an "add" on the one side? If email messages with the same ID differ in their content, ...


4

If BusinessAssembly2 contains all of BusinessAssembly1's public members, then you could write one or more Interfaces for that subset of members, which could be used as a constructor parameter in one or more Facade classes, thereby providing Dependency Injection. That would allow you to switch between either version of the underlying business assemblies at ...


3

Even if it is true that these things will never change, these textures and models are logically part of a specific part of your program: the 3D environment. They only make sense and will only be used within this context. Thus they should not be globals; they should be declared within the relevant context of your program. A basic principle is that all ...


3

In my experience, as a general rule, you should instantiate the underlying object as soon as you have enough information to create it, and destroy it when the scope or object that owns it terminates. In other words, as soon as you know you don't need the information contained in it and can afford the runtime cost of destruction. Considerations include: ...


3

I would recommend typedef-ing all the structs, and putting those declarations in a separate include file. Then define all your actual instances of the structs in whatever your "main" file ends up being. Then, simply include the header and declare the needed instances extern in the other files. The linker will take care of matching up all the references, it ...


3

Good Question! When the service becomes complicated, the number of dependencies will grow more and more In that case your dependencies are maybe not standalone dependencies but can be grouped into simple dependency-holding classes that can be used to pass into the constructor. A good sign would be if more than one of your classes use both IRepositoryA ...


3

I agree with @Ampt's answer. I would add another argument here. Note that you can only ever inherit from one class - I mean, in most popular languages, which happens to include C#. (And even in those where it is possible, such as C++, it is adviced to use this possibility sparringly). So by making your class extend ActiveDirectoryMembershipProvider, you ...


3

Option 4: Authorization Headers and RFC 6750 (Bearer Tokens) The solution you are looking for has already been specified as part of the OAuth2 standard, but it stands by itself and will be useful in your scenario. https://tools.ietf.org/html/rfc6750 All requests from the client will pass in a bearer token (your access token), and it looks like any other ...


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

If you don't need additional layer such as Fabric: Copy files to the server using scp, including the script to run, Run the script through ssh. In both cases, make sure you don't store SSH password anywhere, but use a pair of private/public keys.


2

If you want to give a name to "moving data between related schemas": In Datawarehousing this is called ETL: From Extract_transform_load@wikipedia In computing, extract, transform, and load (ETL) refers to a process in database usage and especially in data warehousing that: Extracts data from outside sources Transforms it to fit operational needs, which ...


2

Creating an interface is the best solution to your problem, and your only arguments against them are: You won't ever have multiple implementations (YAGNI) What I really want is the freedom to add that Interface and alternate implementations later if needed. Interfaces are not just for switching implementations at run-time. Giving yourself ability to ...


2

First I take program to an interface to mean more of programming to a contract rather than programming to a literal Java interface. Contracts can be implemented in classes or interfaces (or even functions). I want to take advantage of this lack of distinction. I also want to interpret the principle "program to an interface" to mean, "I shouldn't ...


2

As I understand it, you have no problem writing OO code. It is in the design phase that you have trouble with. I therefore suggest you study more about Systems Analysis and Design or Object-Oriented Systems Analysis and Design. There are many good books on that topic. Choose one you like. That should help with your "Blank Page" issue, which is something like ...


2

I think there are only two categories of algorithms: Those who rely on versioning and change logs. Basically "give me all of the changes that happened since version #1354." Those who perform extensive comparisons of each side's data. This can be done in O(n) if the ordering is the same. For a client-server problem the former will usually require less ...


2

The main problem with your second approach of injecting factories is that it removes one of the benefits IoC/dependency injection provides - You no longer know which repositories the class depends upon without digging through the code. While this is not as 'bad' as creating the repositories itself, the class still needs to know how to request them from a ...


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 ...



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