abstraction

Why don't numbers support .dup?

╄→гoц情女王★ 提交于 2019-11-29 04:26:37
>> 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 >> end >> end Does this have a downside I'm not seeing? Why isn't this built into Ruby? Most objects in

Abstract private functions

自作多情 提交于 2019-11-29 02:55:53
The following code will have PHP unhappy that customMethod() is private. Why is this the case? Is visibility determined by where something is declared rather than defined? If I wanted to make customMethod only visible to boilerplate code in the Template class and prevent it from being overriden, would I just alternatively make it protected and final? Template.php: abstract class Template() { abstract private function customMethod(); public function commonMethod() { $this->customMethod(); } } CustomA.php: class CustomA extends Template { private function customMethod() { blah... } } Main.php ..

What's the difference between a sequence and a collection in Clojure

纵然是瞬间 提交于 2019-11-29 00:34:29
问题 I am a Java programmer and am new to Clojure. From different places, I saw sequence and collection are used in different cases. However, I have no idea what the exact difference is between them. For some examples: 1) In Clojure's documentation for Sequence: The Seq interface (first coll) Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil. (rest coll) Returns a sequence of the items after the first. Calls seq on its argument. If there are no more

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

三世轮回 提交于 2019-11-28 17:15:31
... 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 know the problem with testing of HttpContext and other build-it ASP.NET-objects. But thanks for good

Why can't an abstract method be synchronized?

不问归期 提交于 2019-11-28 16:52:44
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 someone explain why I'm wrong? The comment about not being able to instantiate the abstract class is

Why is Haskell missing “obvious” Typeclasses

℡╲_俬逩灬. 提交于 2019-11-28 16:38:39
Consider the Object-Oriented Languages: Most people coming from an object-oriented programming background, are familiar with the common and intuitive interfaces in various languages that capture the essence of Java's Collection & List interfaces. Collection refers to a collection of objects which doesn't necessarily have an natural ordering/indexing. A List is a collection which has a natural ordering/indexing. These interfaces abstract many library data-structures in Java, as do their equivalent interfaces in other languages, and an intimate understanding of these interfaces are required to

What is the difference between Abstraction and Polymorphism

隐身守侯 提交于 2019-11-28 16:23:16
I seem to not understand two OOP concepts very well. Could you explain what abstraction and polymorphism are, preferably with real examples and code? Thank you. Abstraction Imagine a fraction class: class fraction: int denominator int numerator Now two objects of that: fraction(obj1): denominator=-1 numerator=-1 fraction(obj2): denominator=1 numerator=1 Both objects have the value 1: (1/1) == (-1)/(-1) . You wouldn't expect they behave any different to the outside. That's abstraction. You abstract the data your object holds into a logical view, even tho behind the scenes, there are other

Is returning IList<T> worse than returning T[] or List<T>?

百般思念 提交于 2019-11-28 15:37:54
The answers to questions like this: List<T> or IList<T> always seem to agree that returning an interface is better than returning a concrete implementation of a collection. But I'm struggling with this. Instantiating an interface is impossible, so if your method is returning an interface, it's actually still returning a specific implementation. I was experimenting a bit with this by writing 2 small methods: public static IList<int> ExposeArrayIList() { return new[] { 1, 2, 3 }; } public static IList<int> ExposeListIList() { return new List<int> { 1, 2, 3 }; } And use them in my test program:

What's the difference between abstraction and encapsulation?

送分小仙女□ 提交于 2019-11-28 15:22:38
问题 In interviews I have been asked to explain the difference between abstraction and encapsulation. My answer has been along the lines of Abstraction allows us to represent complex real world in simplest manner. It is the process of identifying the relevant qualities and behaviors an object should possess; in other words, to represent the necessary feature without representing the background details. Encapsulation is a process of hiding all the internal details of an object from the outside real

Safer compile-time String.format() alternative issue 2

北慕城南 提交于 2019-11-28 06:18:04
问题 With String.format , there seems to be a large opening for programmatic error that isn't found at compile-time. This can make fixing errors more complex and / or take longer. This was the issue for me that I set out to fix (or hack a solution). I came close, but I am not close enough. For this problem, this is more certainly over-engineered. I understand that, but I just want to find a good compile-time solution to this. More information can be found here. My question dealing with Basic