anti-patterns

C#: How to resolve this circular dependency?

I have a circular dependency in my code, and I'm not sure how to resolve it. I am developing a game. A NPC has three components, responsible for thinking, sensing, and acting. These components need access to the NPC controller to get access to its model, but the controller needs these components to do anything. Thus, both take each oth...

Sequential coupling in code

Hi, Is sequential coupling really a bad thing in code? Although it's an anti-pattern, the only risk I see is calling methods in the wrong order but documentation of an API/class library with this anti-pattern should take care of that. What other problems are there from code which is sequential? Also, this pattern could easily be fixed...

Refactoring one large list of C# properties/fields

If you take a look at http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/activedirectoryoperations11132009113015AM/activedirectoryoperations.aspx, there is a huge list of properties for AD in one class. What is a good way to refactor such a large list of (Related) fields? Would making seperate classes be adequate or is there a bette...

Is Domain Anaemia appropriate in a Service Oriented Architecture?

I want to be clear on this. When I say domain anaemia, I mean intentional domain anaemia, not accidental. In a world where most of our business logic is hidden away behind a bunch of services, is a full domain model really necessary? This is the question I've had to ask myself recently since working on a project where the "domain" mod...

Suggestions: Anti-Pattern counter-examples

It doesn't seem that this exact question has been asked before, so I'll fire away: Most of us are familiar with the concept of an anti-pattern. However, avoiding implementation of anti-patterns can in principle swing too far the other way and cause problems itself. As an example, "Design by Committee" has a counter-example that I'd call...

Linq to XML lessons learnt

Hi guys I'm just starting a project which requires some pretty hardcore linq to xml to be used and I am just wondering what people consider best practice and lessons learnt. For instance, I am worried about all the nulls that are possible all over the place... This is something that I am using but how do other people deal with it: ...

Is there a case for parameterising using Abstract classes rather than Interfaces?

I'm currently developing a component based API that is heavily stateful. The top level components implement around a dozen interfaces each. The stock top-level components therefore sit ontop of a stack of Abstract implementations which in turn contain multiple mixin implementations and implement multiple mixin interfaces. So far, so go...

Risking the exception anti-pattern.. with some modifications

Lets say that I have a library which runs 24x7 on certain machines. Even if the code is rock solid, a hardware fault can sooner or later trigger an exception. I would like to have some sort of failsafe in position for events like this. One approach would be to write wrapper functions that encapsulate each api a: returnCode=DEFAULT; try...

Methods calling other methods in the same class

Hi, In class design, is it a bad habit if one method calls another method in the same class (For example, 3 methods call 1 method in the same class). Thanks ...

Naming of an algorithmic antipattern

Hi, I'm having problems to recall the name of doing something with quadratic complexity when it can be solved linearly. For example, using a get-by-index function to iterate over a linked list instead of just using a next-element is the typical case of this antipattern. I think it was the "something painter", as a metaphor of a guy tha...

Where did variable = null as "object destroying" come from?

Working on a number of legacy systems written in various versions of .NET, across many different companies, I keep finding examples of the following pattern: public void FooBar() { object foo = null; object bar = null; try { foo = new object(); bar = new object(); // Code which throws exception. ...

How to deal with null value in <select> HTML filter ?

I have an user interface that print user, and I wan't to have a filter by country. I made a classic <select /> element. In JSP I have <select id="country" onchange="return filter();"> <option value="">...</option> <c:forEach var="country" items="${countries}"> <option value="${country.id}" ${country.name} ...

Is this hardcoding? How can I avoid it?

I'm creating a parser for a specific XML structure and I'm facing a possible hardcoding issue. Here: private function filterDefaultParams($param){ #FIXME Hardcoding? return array_key_exists('default',$param); } The literal 'default' is a valid tag in the Xml structure, is this hardcoding? May I use another technique to search ...

Creating custom events - Object Sender or Typed Sender?

I searched through the archives and I found lots of questions about what sender is and why you should use the pattern but I didn't see anything about a custom event and the type if sender. Say I am creating a custom class called Subscription and it implements ISubscription and I have some event args called SubscriptionEventArgs. If Subs...

Is using D string mixins for code reuse an anti-pattern?

For those of you who are not familiar with D string mixins, they're basically compile-time evals. You can take any compile time string (whether a literal or generated by template metaprogramming or compile time function evaluation) and compile it as code. If you use a simple string literal, it's basically compiler-automated copy-paste....

Is it ok to implement State pattern here?

Hello, I have a Request class that can be in one of the following states: Draft, Submitted, Approved, Rejected, InMission, Completed The state of the Request object can be changed by calling one of the following methods. Each method may include some arguments to further associate some data with a particular state: void Submit(...

Top misrepresentations in programming?

I often find that design patterns, libraries, and frameworks promise great things and sound awesome - until you actually study them and realize that what they say sounds better than it actually is. Completely modular and stackable - use only what you need! For example, how do you properly Unit Test your database if your applica...

I'm in an anti-pattern and I want to get out.

I am developing a java webapp, using jsp/jquery/ejb/jboss. I have a web-form that enables the user to select any combination of 100 fields (all from different unrelated tables/objects) from the database. These fields are then output, via a java servlet, to an excel spreadsheet. A stored procedure is executed that always returns all 100 ...

OutOfMemory Error java heap space

I'm using this statement //some code int a[][]=new int[5000000][5000000]; //some code and running it with command java -mx512m Test It is giving OutOFMemoryError: Java Heap space indicating the line number of the mentioned statement in the stacktrace How do i solve this problem Edit: I'm trying to solve a practice problem on cod...

What to do about a 11000 lines C++ source file?

So we have this huge (is 11000 lines huge?) mainmodule.cpp source file in our project and every time I have to touch it I cringe :-) As this file is so central and large, it keeps accumulating more and more code and I can't think of a good way to make it actually start to shrink. The file is used and actively changed in several (> 10) ...