Tag Info

New answers tagged

0

Agree with the previous answer. As mentioned there, the model types mentioned in the question will not help you alone. In case of a non-trivial data model or business domain, I recommend to start with an entity relationship diagram. It is easy to understand, the few symbols are quickly explained. Include proper definitions of the entities. This will make ...


0

With any architectural modelling and representation you have to consider your audience and what notations will most easily and accurately communicate the designed structures as well as rationale for those decisions. Two good things -- Using a documented and "standard" architectural style (SBA) helps with communication by way of pattern recognition. If ...


0

There will be 24 different orientations for your character. So you definitely don't want to go with if/then/else statements. If you describe your character orientation as a 3x3 matrix (consisting of 0, 1 and -1) then each type of turn is achieved by multiplying that matrix by a rotation matrix (also 0,1&-1).


9

Aren't we breaking the Single Responsibility Principle with this super-mega-god-interface? Not exactly, because the interface isn't doing anything. It has no responsibilities. You are breaking Liskov Substitution Principle and Interface Segregation Principle though. LSP because you're writing methods that do nothing, just to make it fit the interface ...


1

Solution 1 violates not only Liskov's Substitution Principle but it also violates the Interface Segregation Principle and the Single Responsability Principle. Solution 2 is the correct approach (see correction at the bottom). Same as above You can do that and solution 2 at the same time, they are not exclusive. You should use non-OO solutions and patterns. ...


0

The method I prefer is based on a factory design pattern (which is different that most unit testing frameworks for .NET, but since you are designing your own framework starting from scratch may be ok). In this scenario each common test case is a class unto itself (based on a common TestCaseBase class) then you have a factory that generates each test case, ...


1

I tend to plan more in projects, which are similar to those I already did. Because I know what worked last time and what didn't, so I can get more into details in the planning about the architecture. When I do something new, I have a vague idea about what I have to do. But start coding right away and throw the bad ideas out early has proven to be a better ...


6

When making traditional estimations, my experience is that the effort distribution is roughly 30% design, 40% implementation, 30% test and usually the design is considered complete when you have identified the relevant classes, their responsibilities and optionally the major methods. One of the risks that you run when doing a very complete and comprehensive ...


1

I don't think that you have to use some "90%" as golden rule, just use what is best for YOU. I would think of it as guide line to spend more time on thinking how to do it, instead of trying by permutation. Just say loud NO to "golden rules", use them as indicators yes, enforce them never.


3

First, it depends on the kind of project. Is it similar to something you have already done, repeatedly? Then your coding part can be extremely short. On the other hand, if it is completely new, with a lot of new functionality, then you probably need to code a lot of functionality. (Well, or use an existing library. Which needs to be tested. Is testing of a ...


1

I agree with your reasons to choose option #1. If the e-mails you send won't clog up your Internet connection, why should they clog up the network connection between your web application and your queue processor? There is always a trade-off between code maintainability and performance. However, since you state yourself that performance problems with option ...


1

The Object can be in one of many physical locations, while it can also be in one of several stages of processing ... This got me thinking about the Bridge Pattern. For structure. (The object might move back and forth between locations, or back and forth between the stages of processing). This got me thinking about the Visitor Pattern. For ...


1

Of course it depends on how the function is meant to be used. These are really two separate (though not independent) design decisions: What counts as invalid input? What to do about invalid input? About that first decision, any of "+3", "03", "0x3", "3.0", "3.", "3e0", "3 ", " 3" could in some domain reasonably be declared a valid or invalid int ...


1

There's another potential answer here, and I think akalenuk hinted at it. Use a maybe monad or some other similar, option type. For example C#/.NET has Nullable<T>, which isn't the same but is pretty close, but restricted to Nullable<int> it should be enough. public static Nullable<int> toInt(string s) { int i = 0; if ...


3

ISP is an interesting principle because the benefits (or rather the costs of ignoring it) are generally small, but the cost of implementation is also small. The kind of problem that might occur is if, at some point, you want multiple strategies for getting an internal interface, but only one for getting an external interface (or vice versa). And you're ...


3

ISP basically says that it's not good to require from a class to implement unrelated things, and/or make a client require unrelated things. Methods in an interface are related — a client may need all of them to complete some reasonable task. I think getInternalID and getExternalID belong to separate interfaces, since clients wanting one of these don't need ...


1

Why do you only need one string-to-int method? Why not three: /** Throws exception if string is unparsable */ int strToInt(String s) throws NumberFormatException /** Returns null if string is unparsable */ Integer strToIntOrNull(String s) /** zero if string is unparsable */ int strToIntOrZero(String s) Now the client of your code can choose and know ...


1

Considering that 0 has been invented to fill a void in positional representation of numbers, Considering that most spreadsheet applications interpret an empty cell as a 0 value and that this behaviour is expected by users, It is not far fetched to convert an empty string to an integer of value 0. The reverse conversion doesn't need to be symetrical ...


3

The best solution would be not to convert it at all. Throwing exception or using some kind of "maybe" type with an error instead. But if you absolutely have to find a matching integer for an empty string, try focusing on a least harm principle. Say, if empty string is a valid input for "i don't care", then 0 might be ok. Because why not? 0 is an any ...


2

If you're converting string to int similar to JavaScript's parseInt function, then you would probably want to have '' return NaN or throw an exception, as you said. JavaScript returns NaN, but if your language doesn't have that convention or feature you should throw an exception or return a null value.


7

An empty string doesn't represent any integer, so at face value your question has a trivial answer - do not convert an empty string to a valid integer. The question behind the question seems to be "how to design a robust non-surprising string-to-int conversion utility". This is tricky - consider the following additional cases: What string number ...


1

What I understand from your example is that your object can be represented by two parallel state-machines (location and stage), and you need to synchronize those automata. You could take inspiration from Statecharts, for example, which allow hierarchical state-machines with communication across states, among other things, but this is likely to be overkill ...


3

Your different states sound more like activities. If they were states you would use Nouns to describe them (example; "full", "empty", "box", "container"). If they were activities then you would use Adjectives to describe them (example; "opening", "processing", "making"). Your object can be at a given location (i.e. a state), but it's doing many things at ...


1

Sounds like your object needs a location field (and maybe a location class or interface to help ensure valid values) and a second field for processing stage which could probably be represented by an enum of the possible stages. enum ProcessingStage { STAGE_1, STAGE_2,... STAGE_N; } class MyObject { String location; ProcessingStage stage; ... } ...


1

If I understand your question correctly, you could design your code similar to the outline below: A StateObjectContainer class that holds references to the current state, the object, and to the state manager. This class is responsible to the metadata (the references) associated with the contained object. A State class with a collection of ...


1

2. Have a larger Superclass that handles which states O is in, and handles the interactions. That sounds like an awful lot of logic from what you are describing. Do you want the same class defining that 30% complete parts in Atlanta have to be shipped to Dallas as the class that handles 99% complete parts in the East part of Dallas can be moved to ...


0

You could specify an interface, say IValidatable and use reflection to loop through all the properties and sub properties and validate any which implement the interface. You then only need to implement Validate on each small sub property. Many of the properties are dependent on each other means they have some sort of dependencies. This is the root of ...


0

Well, if you want to get rid of those switch statements it's a good idea to use polymorphism to validate objects (e.g. making MyBigClass a class which is supertype for your vehicle brands). The benefits of this approach are: You can use dynamic dispatch for methods like validate which are abstract at MyBigClass Level and are implemented in the specific ...


2

Well, depending on the complexity vs. load of your application, Spring Batch may or may not be a good solution. This is strictly a personal opinion, but I've found that, while Spring Batch let's you quickly prototype some batching mechanism (you only have to implement the business logic, all the batching mechanism comes out of the box) it can prove slow if ...


0

This will be a partial answer since I'm not a regular user of Java (more of a C++ guy myself). Here's a few ideas that could guide you : 1) If a attribute may be edited by multiple sources (a Stat calculated with a base value, bonus/malus from a skill and bonus from multiple lifepath), perhaps should you not save it as a single value, but as a association ...


0

Separate interface from implementation. "PlayerCharacter" should be an interface with methods like "getStats", "getContacts", "getReputation" etc. This gives you freedom to play with the implementation without having to change the code which uses this interface. The implementation can choose to cache values and recompute them if necessary. For example a ...


3

I strongly suggest you to have both artificial data in one or more small test files to check each requirement on its own (maybe for unit testing) one or more production files of a certain size to check things you did not think of when designing your artificial data (this gives you an integration test) To my experience, the chances are high that those two ...


0

I would just have one table for users and a one table for user_columns. The whole notion of users dynamically adding tables is not one I'd tackle. The user_columns table would have user_id as a non-unique foreign key, plus columns such as description, timestamps, etc. That way you just add and remove rows from user_columns as needed.


-1

You can create tables by users like which user create tables append her name at start of the tables e.g john_emp; john is the user who created the table and emp is the actual table name by this approach you can figure out the who created the table or you can say you develop the group by users' table.


7

There is absolutely a way to avoid checking for null here! Use the null object pattern, i.e. class NullStrategy: Strategy { public void doSomething() { } } and then the "default" case in createConcreteStrategy is return new NullStrategy() instead of return null, and then you no longer have to check if strategy is null in run. If you don't want ...


2

Yep, this would be great in theory… Indeed, naming design patterns improves readability. This is actually the goal of design patterns in the first place. It's much simpler to say: I used an abstract factory, but maybe we should start switching to a builder for more flexibility. to your colleague when explaining the structure of your code, rather than: ...


4

IMO this is a false dichotomy. If you follow SRP, you keep your system simple overall. Multiple small classes tend to be more "simple" (in many cases) rather than fewer large classes. Plus it seems like you are conflating two issues: how you design your classes vs. how you design your database. The two do not need to be related. In your given case, it ...


3

You're confusing KISS; simple isn't referring to simple to implement for the developer, it refers to simple design, simple to understand and use. Following SRP makes your code simpler to understand and use because it's simpler to use a purpose built class for a single purpose than a multipurpose class, it's also simpler to maintain. SRP supports Simplicity, ...


1

It looks like you're using an Access-to-Access setup, with the forms, reports, and queries in one *.accdb file and the tables themselves off in another. If you want better control of the queries, move them -- ALL of them -- into the back-end accdb. The queries belong with the tables, and the only exceptions should be exceptional, with clear and distinct ...


0

I now use a completely different solution, namely for each entity a separate service must be created. That service can extend the one provided by my framework and optional add additional methods. This gets rids of the configuration above because you don't need any constructor arguments anymore: <bean id="testCompoundService" autowire="byType" ...


0

The solution I used is this: And to reference the image in the question, a Batch extends Containable.


0

I hope I'm understanding the problem correctly, but one solution I've seen is to have the receiving program implemented as a local server, listening on a specific port (for security, have it only accept localhost connections). I don't think there would be much in the way of performance lag. This leaves the idea that someone might send voice commands from ...


0

I have no idea how Go works, but an architecture I have used in ActionScript is to have a Doubly Linked List that acts as a Chain of Responsibility. Each link has a determineResponsibility function (which I implemented as a callback, but you could write each link separately if that works better for what you're trying to do). If a link determined it had ...


1

No. It wont be a good design. Especially since the mysql_* functions are already depreciated. Start using prepared statements. Start using PDO.


2

You don't seem to picture the design of your system very clearly yet. So a bit of advice: Make it as simple as possible. Write down several scenarios of interaction between the user and your program. Be careful to include cases when the user changes his mind in the middle of saying a command, and other scenarios when things go wrong. Don't proceed until ...


1

The counter-question is, what is the apparent probing interval you want to present to your users? If the apparent probing interval should be the actual probing interval, you should only present actual data points to the user without interpolation or extrapolation. If the apparent probing interval should be a real-time status, you should extrapolate the ...


0

Even hashing the password and sending it via GET or POST is a serious breach if you only send it via HTTP - anyone can intercept the plaintext request and use that hashed value to access from anywhere else as that user. If you're going to do this kind of thing, you absolutely should be using HTTPS - with a proper certificate from a recognised authority. ...


3

Just do a HTTPS POST in your launcher application, passing through the username+password normally. That's how your web browser does it.


1

Don't send even hashed passwords in plaintext and especially not in the URL. A time-limited token is much less valuable to an attacker. Use a cryptographically secure random generator to create a unique token for each user. You'll need to work out how to issue new tokens when the old ones expire. This is how most email-login links work.


5

There's nothing inherently wrong with mutable subclasses provided you don't make assumptions about mutability in other parts of your code. As an example, the Foundation framework that's part of Cocoa and Cocoa Touch frameworks (MacOS X and iOS respectively) has a number of immutable data containers that have mutable subclasses. NSMutableArray is a mutable ...



Top 50 recent answers are included