Tag Info

Hot answers tagged

7

Whenever you feel an urge to inspect the dynamic type of your polymorphic objects at run-time, you should question your design. This is true for any object-oriented language I know. The visitor pattern can be of great help in avoiding to bother with the dynamic type of an object. Some people seem to think that cheating around type inspection by adding a ...


6

Architect the system so that the algorithms aren't deployed to a machine that an attacker controls. Generally, this will involve hosting the component that implements the algorithms on a server you control and using the client to simply gather input and display the output of the server component. But you could also build the entire thing as a web ...


5

If func_2 in MyClass1 doesn't contain any logic and is expected to be declared by child classes (and MyClass1 is never used directly), then making the class abstract like you did is a reasonable approach and makes the code self-documenting and explicit. If: func_2 in MyClass1 contains logic (eventually overwritten in child classes), Or MyClass1 may be ...


4

Which class should know how to convert a new A to a legacy A? Maybe it's the A class itself which has this knowledge. It may know how new and legacy values are mapped, which fields should be added or removed, etc. In this case the following approach seems quite natural: A legacyA = a.toLegacy(); The benefit of this approach is consistency: it's similar ...


4

The test to apply is whether or not someone can definitively understand the intent of the arguments just by looking at them. In your example, the interpretation of --opt=foo would vary depending on the program's surroundings. That could sow confusion or, worse, cause a security problem if there's a file named foo in the current working directory and the ...


3

Having a separate business tier needs justification as it involves lots more work and costs more in performance (see: MS-Business Layer). According to one definition of Web Services, a Web Service is not generally required unless you are communicating between different physical tiers. Accordingly, a DLL may fit best for what you describe. It is common to use ...


2

You've seen programs that interpret option arguments both as a filename and as literals? Depending on what, the state of the file system? That's an insidious defect or exploit waiting to happen. Never, never, ever do this.


2

This sort of problem is well-suited to dynamic typing. That will give you the most straightforward solution, with the obvious trade offs. If you wish to use static typing, you'll have better luck if you don't centralize your pipeline construction. Your stages are the ones who know the most about the types of their dependencies and results, so you should ...


2

Validation of input parameters/data should be performed whenever the data can come from an untrusted source. To be on the safe side, if anyone outside the development team can supply data to an interface, then that interface should validate its inputs. The more interesting part of the question is what to do when the validation finds a problem. First of ...


2

Asking this question shows that you find your current model not intuitive and I think this is a good feeling. Let me explain an alternative to having only Student, Subject and Degree to you that hopefully feels more intuitive. While a student might seem to know everything about his degrees, he doesn't. Let's illustrate this with a real world example: ...


2

Have you had a look at existing libraries e.g. spring quartz or spring batch (I'm not sure what fits your needs most)? To your question: I assume the problem is, that you want to persist some metadata to the task in a polymorphic way, so an e-mail task has e-mail addresses assigned, a log-task a log-level, and so on. You can store a list of those in memory ...


2

If your entire stack is .net there is not much value to creating web services. Just reference the DLLs in the .net components that need them, it will be faster as there is no serialization or extra network hop involved. However, for cross platform purposes, web services are the way to go. Then you can have a .net client (ASP MVC app), java client, native ...


1

A lot of questions of this kind depend heavily on the actual business domain, and it's not clear that we have enough information to make a good decision. any rebind is treated as non-normal situation This comment suggests that it may make the most sense to send back a error response (e.g. 400 Bad Request) with a description of the reason you're not ...


1

The scenario you describe assumes that when the software is re-installed on a device, that your system will recognize that device as having been seen before. This will only happen if, as part of the registration, the device must send some hardware identification. If you don't use such pre-existing hardware identifications, but you assign an ID after ...


1

I would say Option 1 is the best route to take. The reason you should not dismiss it is that the SendEmailTask is not an entity. An entity is an object concerned with holding data and state. Your class has very little of that. In fact, it is not an entity, but it holds an entity: the Email object you are storing. That means that Email should not take a ...


1

I've been developing extensible software for a long time now. I've also been on the other side. One thing I've learned is that you want libraries you use to "Fail fast". What that means is, it should break my software as soon as possible if something is wrong. If you can (which in this case I presume you can't) break at compile time. If not, throw an ...


1

It is perfectly fine, as long as the class hierarchy on which you are doing this is small, self-contained, and not liable to be extended by someone who is not at liberty to refactor it. The visitor pattern is not a bad idea, but it is a hassle to implement, and more importantly, every time you try to read it, you are forced to read a lot of code. Compare ...


1

You could have a factory which provides the correct adapted object. Exposing a series of classes or a single class with multiple methods assumes that you have some knowledge before hand of the system. Another (problematic, I think) issue is that by exposing all the adapters you are giving the caller (client) complete control over which adapter gets called. ...


1

One option is to make it clear to the IDE and your users that there is a method, but you can't use the base class version: class MyClass1(object): def func_2(self): raise NotImplementedError def func_1(self): return self.func_2() * 2 You won't get warnings from intermediate classes that don't define func_2, but will get an error ...


1

Student, Subject and Degree are not directly related. A StudentDegree would have the knowledge and reach to know about students, subjects and their degree. A subject should not track what each student scored. A StudentSubject should. A student should have one StudentDegree. A StudentDegree has a Student, and many StudentSubjects and Degree. Now you've got ...


1

First: What is the program supposed to do? You cannot make decision about architecture without knowing the purpose of the program. Also, ignore advice from people whom you haven't told the purpose of the program :) Second: Unless you are writing an actual simulation of a college, you probably don't want objects like Student, Subject etc. to have behavior ...


1

If you want to associate a Student with a Degree, but keep them separate from each other, you can express that relationship with a data structure like a HashMap. something like (untested, treat this as pseudo code): HashMap<Student, Degree> enrolment = new HashMap<Student, Degree>(); Student dave = new Student(); Degree masterOfScience = new ...



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