New answers tagged

0

Instead of checking and invoking specific makeComboBox vs. makeNumericTextField, consider invoking a generic constructUI, which would be a virtual method on the base class FormElement that is overridden by the various subclasses, each of which does the equivalent. The idea behind OOP is to instruct the object to do something useful on its own and return to ...


1

the classic way is to use a Factory class with your switch Factory.Create(data) { switch data.class case : combo return new Combo(data) .... } this can be made more generic using reflection until you end up with a dependency injection container container.Register<FormElement,Combo>().Named("combo") container.Resolve<...


1

The way your question is written makes using multiple threads seem pretty much pointless. However, a couple of examples where you might do this that are similar to what you describe. TIMEOUTS - If you don't want A to take longer than some specific amount of time then you'd possibly start B running on a separate thread while thread A is waiting for a ...


0

TypeScript is another typed language that supports intersection types T & U (along with union types T | U). Here's an example cited from their documentation page about advanced types: function extend<T, U>(first: T, second: U): T & U { let result = <T & U>{}; for (let id in first) { (<any>result)[id] = (<any&...


2

Arrays are very low level. You could as well ask, "In java why are int, float, and double not objects, to make them more consistent with the rest of the object-orientated language?" Arrays have a close mapping (in most languages) to the assembly level memory code. This has no real notion of generics, arrays are of pointers or other primitive types. Arrays ...


5

In Java, there is no Array type collection to make arrays feel more consistent, such as in inheritance. Sure there is, it's called List<T>. The only fundamental difference between a hypothetical Array<T> and List<T> is that you can't resize the Array<T>. If Array<T> were added it would be just like List<T> except with ...


3

Regarding Java, Java 1.0 didn't have generics. On the contrary, I'd argue arrays are "first-class citizens" in Java since they're given special treatment by the language. It's true that sometimes you simply need a fixed-size collection, but the case where you need a dynamically-sized collection is more common. Finally, arrays are fine for temporary usage ...


1

This is a very general question so the answer can be unavoidably "it depends". As an example, JPA (Hibernate) and Entity Framework are attempts to create abstraction over (mostly relational) databases - so that your app is agnostic of the actual SQL database engine it is running on. That's great, but it's not free. What you get is more flexibility (you can ...


0

The jury is still out on this question. There are costs (consequences) no matter how you choose. There are many ways to classify and compare the consequences, but the basic ones are: Effect on development cost / productivity Effect on product quality as judged by customers (e.g. lack of defects and functional limitations) Effect on maintenance Capability ...



Top 50 recent answers are included