abstraction

Level of Indirection solves every Problem

徘徊边缘 提交于 2019-11-28 05:17:15
What does the quote "Level of Indirection solves every Problem" mean in Computer Science? Generally it means that by increasing the level of abstraction one can make the problem easier to understand/resolve. Be careful with your abstractions though, the full quote at least as I heard it is, "You can solve every problem with another level of indirection, except for the problem of too many levels of indirection". From the book Beautiful Code : All problems in computer science can be solved by another level of indirection," is a famous quote attributed to Butler Lampson, the scientist who in 1972

Difference between Encapsulation and Abstraction

丶灬走出姿态 提交于 2019-11-28 02:50:59
I had an interview today. I had a question from OOP , about the difference between Encapsulation & Abstraction ? I replied her to my knowledge that Encapsulation is basically to bind data members & member functions into a single unit called Class . Whereas Abstraction is basically to hide complexity of implementation & provide ease of access to the users. I thought she would be fine with my answer. But she queried, if the purpose of both are to hide information then what is the actual difference between these two? I could not give any answer to her. Before asking this question, I read other

Command Pattern seems needlessly complex (what am I failing to understand?)

…衆ロ難τιáo~ 提交于 2019-11-28 02:49:33
问题 I've read up on the Command Pattern, and I think I'm missing something. The Command object exists to abstract away the details of the Receiver object. It seems to me that we could simply stop here, and hold references to Command objects to execute the appropriate method at the appropriate time. Why, then, is the Invoker needed? What advantage does this additional indirection provide? We've already hidden the details of the Receiver behind the Command, what's the motivation for the Command to

When should I return the Interface and when the concrete class?

左心房为你撑大大i 提交于 2019-11-27 22:46:35
when programming in Java I practically always, just out of habit, write something like this: public List<String> foo() { return new ArrayList<String>(); } Most of the time without even thinking about it. Now, the question is: should I always specify the interface as the return type? Or is it advisable to use the actual implementation of the interface, and if so, under what circumstances? It is obvious that using the interface has a lot of advantages (that's why it's there). In most cases it doesn't really matter what concrete implementation is used by a library function. But maybe there are

Should I use public or private variables?

淺唱寂寞╮ 提交于 2019-11-27 19:08:13
问题 I am doing a large project for the first time. I have lots of classes and some of them have public variables, some have private variables with setter and getter methods and same have both types. I decided to rewrite this code to use primarily only one type. But I don't know which I should use (variables which are used only for methods in the same object are always private and are not subject of this question). I know the theory what public and private means, but what is used in the real world

Why don't numbers support .dup?

荒凉一梦 提交于 2019-11-27 18:20:01
问题 >> a = 5 => 5 >> b = "hello, world!" => "hello, world!" >> b.dup => "hello, world!" >> a.dup TypeError: can't dup Fixnum from (irb):4:in `dup' from (irb):4 I understand that Ruby will make a copy every time you assign an integer to a new variable, but why does Numeric#dup raise an error? Wouldn't this break abstraction, since all objects should be expected to respond to .dup properly? Rewriting the dup method will fix the problem, as far as I can tell: >> class Numeric >> def dup() >> self >>

Why should I use a human readable file format?

蓝咒 提交于 2019-11-27 18:06:09
Why should I use a human readable file format in preference to a binary one? Is there ever a situation when this isn't the case? EDIT: I did have this as an explanation when initially posting the question, but it's not so relevant now: When answering this question I wanted to refer the asker to a standard SO answer on why using a human readable file format is a good idea. Then I searched for one and couldn't find one. So here's the question Nick Fortescue It depends The right answer is it depends. If you are writing audio/video data for instance, if you crowbar it into a human readable format,

What is Google's Dremel? How is it different from Mapreduce?

人走茶凉 提交于 2019-11-27 17:31:59
Google's Dremel is described here . What's the difference between Dremel and Mapreduce? Check this article out. Dremel is the what the future of hive should (and will) be. The major issue of MapReduce and solutions on top of it, like Pig, Hive etc, is that they have an inherent latency between running the job and getting the answer. Dremel uses a totally novel approach (came out in 2010 in that paper by google) which... ...uses a novel query execution engine based on aggregator trees... ...to run almost realtime , interactive AND adhoc queries both of which MapReduce cannot. And Pig and Hive

System.Web.Abstractions: what is it good for?

社会主义新天地 提交于 2019-11-27 10:20:25
问题 ... absolutely nothing? What part of the puzzle does it fill for ASP.NET WebForms and ASP.NET MVC respectively? Can you somehow create a ASP.NET * base-application which uses System.Web.Abstractions so it can be used in both kinds of ASP.NET-web applications? In that case, how did they retro-fit the classes in System.Web.Abstractions back into ASP.NET WebForms? You can't new up objects from the namespace, so it can't be used for mocking, can it? Update : Sorry for not being clear on that I

Why can't an abstract method be synchronized?

久未见 提交于 2019-11-27 10:01:37
问题 I was reading a thread from CodeRanch saying that abstract methods could not be synchronized due to the fact that an abstract class cannot be instantiated, meaning no object to lock. This doesn't make sense since an abstract class is a definition (contract) for a child class. The abstract definition of a synchronized method does not need to lock, the child does. All the abstract heading would indicate is that the child must synchronize this method. Is my logic on this correct? If not can