Tag Info

Hot answers tagged

93

No, an object does not have to represent an entity. In fact, I would argue that when you stop thinking about objects as physical entities is when you finally get the benefits that OOP promises. This isn't the best example, but it's probably where the light started to come on for me: http://www.objectmentor.com/resources/articles/CoffeeMaker.pdf Objects ...


80

Code that works for you and is easy to maintain is by definition "good". You should never change things just for the sake of obeying someone's idea of "good practice" if that person cannot point out what the problem with your code is. In this case, the most obvious problem is that resources are hard-coded into your application - even if they're selected ...


20

Can classes represent entity-less objects? If not, why they are bad/incomplete/non-OOP-centric? Are there ways they need to be changed/improved? In short, you can do anything, but this specific scenario would be against OOP principles :) What you are describing is sometimes called a "utility" class - usually a sign of code smell. You want to avoid ...


15

Can classes represent entity-less objects? Can? Yes. Should? Probably not - or at least, not how you're phrasing things. Objects actually are best when not representing a physical object directly since reality so infrequently maps nicely to code. But they do need to represent a cohesive concept or code-object. They need to represent a single cohesive ...


13

You are absolutely right in thinking this is a bad practice. I've seen this in production code, and it always comes back to bite you. What happens when you want to add another environment? Or change your development server? Or you need to fail over to a different location? You can't because your configuration is directly tied to code. Configuration should ...


10

A class should model something - otherwise it's pointless. However, what's being modeled may not be a physical "thing"; instead, it may be a representation of something which is not 'real', but which is needed to control the system being modeled. For example, in a traffic light control system you could very well have some sort of ControlSignal class, ...


8

The real and complex numbers are uncountable. Regardless of what representation you choose, almost all of them cannot be stored on anything that could be considered a computing device. The closest you can get is the computable numbers, but testing two computable is undecidable. Even disregarding that, it's not a very practical representation. Some sort of ...


7

No. (Title edited to ask the opposite question!) eg: Public class MyRepository { public MyObject GetObject(string id) { //get data from the DB and build an object } } or Public class MyService { public MyObject3 ProcessData(MyObject1 obj1, MyObject2 obj2) { //perform a process which is not a sole responsiblity of ...


6

if (first<second) In this case, there is something different involved here, the operator< from std::basic_string. and was wondering if alphabetical string characters are assigned numerical values for the purpose of comparison. No, not really. You don't assign a number to a character just for comparison. A computer does not know anything about ...


5

Does an object have to represent an entity? Question: Which entity does a Logger represent? Not metaphorically - literally. When explaining OOP to students it is helpful to explain objects with analogies to the physical world. Alan Kay - one of the fathers of OOP - wrote the following: [...] The original conception of it had the following ...


5

I think that visualizing something in the real world is helpful when coding classes but not necessary. In fact, depending on how literal you want to be, many objects we work with don't have physical representations at all. For instance--consider MVC architecture. In the real world there is no Model or Controller even though they are generally represented ...


4

For one, (as others have mentioned) this is a bad idea because you're tying implementation details into your code. This makes it difficult to change things. As mentioned in this answer, if you want to add a new environment now you have to update your code everywhere, instead of just adding your program to a new environment. There is another serious flaw ...


4

I assume you mean "get rid of accessors and make private members public"... well, from a design point of view, a getter/setter is not doing much more than a public variable anyway, just with more layers. Now, a good class design would not even begin to consider exposing a variable at all, it instead adds methods that apply to the internal state of the ...


4

Transact-SQL is a Turing complete language. (See Is SQL or even TSQL Turing Complete? for details) declare @num int if @num is null print 'it is null' else print 'it is not null' produces it is null


3

It seems that with this type of architecture developers no longer have to maintain large codebases, and the applications themselves are mostly thin wrappers around databases. You've fallen into the NoSQL mindset. "Hey, why should we learn this complex thing called SQL that the old-timers use? Why don't we just use a giant key/value store for ...


3

Yes, you can do this. But you're essentially creating a class to provide the same functionality as a procedural library. The only reason to do that is if your language lacks procedural modules (e.g., Java or Ruby). In a language with procedural modules (I think PHP has procedural modules), you might consider just using a procedural module. You could also ...


3

In layman's words What you describe is called an utility class. I has no state, meaning you will not ever really need to have several instances of it All methods are static, meaning you have to pass everything as parameters Such classes do exist, for example the Java SDK has the Collections class which consists exclusively of static methods that operate ...


2

From what you describe, it sounds like you are looking for a potent preprocessor to generate the code that is subsequently compiled. Preprocessors are, of course, almost as old as computer languages themselves, however, most are really limited in extend and syntactic capabilities. Afaik, there are basically two kinds of preprocessors: Non-turing complete ...


2

What you are looking for is called a REPL, a quick search for "C++ REPL" gets you to Cling, but I have not used it. I'm not sure what is the real benefit from using a REPL over to use a debugger with an interface that you are comfortable with. Static typing should help you get the code right before ever running it, also IDE's suggestions become much better ...


2

No, a class merely represents something that can be instantiated, has members, and can be inherited from. In fact, your language may have static classes, which are not even instantiated more than once. .NET's Math is a great example of a "professional" class that represent no entity (unless you want to get philosophical about what math is...), and also ...


1

I use a two state, two stack model similar to the Shunting Yard algorithm. The two states are the unary state and the binary state. In each state, you handle tokens (or issue errors) and then either continue the same state or switch to the other state. In the unary state, if you find an open paren, (, it is operator grouping, and, you stay in the unary ...


1

It's an opening bracket which follows directly after a identifier. So when you meet a open bracket you check whether the last token you parsed was a identifier or a operator. If it was an operator then it's a just a subexpression if not then it's part of a function call. Comments should be dealt with before the you parse the token stream. This turns you ...


1

Arguably the reverse is true; microservices are attractive because of limitations of the languages currently used. This is why you see two distinct camps in microservices: small ones written in dynamic languages that lack a built-in usable concept of a documented and statically checked interface. So they build one themselves out of HTTP and tests. Much ...


1

I think the paintCar function makes more sense if you provide a reference to the car object and the colors of the garage and favorite. function PaintCar (favoriteColor, garage, car) { //The test succeeds if the favoriteColor boolean value is true. if (favoriteColor) { return car.color = favoriteColor } // The test succeeds if either condition ...


1

The answers to your questions ultimately hinge on how precisely one defines terms like "class" and "entity." You did a good job of defining the latter, allowing both physical and conceptual entities. But the term "class" to purists will always be "a factory for instantiating objects with a particular internal representation" and to pragmatists the term will ...


1

What if I want to run the backend on my own machine but not on port 55793, for example if I were running multiple versions at the same time to compare them? What if I want to run the application backend on one machine, but access it from another? What if I want to add a fourth environment? As others have pointed out, you have to recompile just to change the ...


1

NIM http://nim-lang.org/docs/tut1.html Provides arbitrary compile-time calculations with whole feature set of runtime.


1

"I'm really interested in writing my own general-purpose high-level programming language" Are you really? If you are truly interested and want to create your own language complete with a (native) compiler for the experience you would probably be interested on reading up on assembly and how the CPU works, you can examine the assembly output of existing high ...



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