Matches in SemOpenAlex for { <https://semopenalex.org/work/W2340148237> ?p ?o ?g. }
- W2340148237 abstract "class Number virtual instance methods: sum: Number -> Number difference: Number -> Number product: Number -> Number instance methods: sqr() = product(self) end class Figure 20.5: Class Number with virtual methods. The sqr method can use product, even though product is not defined here. The class is abstract to indicate that it has at least one virtual method. the derivative, the derivative method is virtual, and the methods for each kind of data are placed with that kind of data, in its class. When a single type with variants is used instead, as done in Chapter 14, adding a new kind of expression requires modifying functions by adding a new case to each that handles the new kind of expression. But the object-oriented approach avoids that. Adding a new kind of expression just requires adding a new subclass of Expression and defining the virtual methods for that class. There is no need to modify any existing classes or methods at all. Now imagine providing expressions and symbolic computation on them in a library. Keep in mind that most programmers are not allowed to modify the library, but can only use it. The single-type approach allows the writer of the library to include a fixed collection of expression forms, but does not allow anyone else to add new expressions. Classes and virtual methods allow anyone to add new kinds of expressions in his or her program without modifying the library at all. Sometimes you do not want to add a new variation but to remove one because it is no longer needed. That is also easy to achieve using the object-oriented approach; you just remove the subclass that implements that variation (and any place where constructors of that subclass are used). There is no need to modify the implementations of other classes. 20.6.3. Virtual methods as function parameters Some programming languages allow you to pass functions as parameters to other functions, but most object-oriented languages do not allow you to do that. But sometimes you can simulate function parameters by using virtual methods. Suppose that you want a function or method, time(f), that runs another function f and tells you how long f takes to run. In an object-oriented programming language, you create a class called Timer, as in Figure 20.6, containing a virtual method called run that represents the function that is to be timed. It is a hook where the actual function can be attached. To time a function, you define a subclass of Timer where the run method runs the desired function. Instead of asking one object to time the execution of a method in another object, you let the subclass inherit the time method, so an object of the subclass knows how to time itself. Chapter 10 showed that the ability to pass functions as parameters to other functions allows the creation of versatile libraries containing functions that implement entire classes of algorithms. Virtual methods in class libraries can be used to achieve similar generality." @default.
- W2340148237 created "2016-06-24" @default.
- W2340148237 creator A5060334068 @default.
- W2340148237 date "2011-01-01" @default.
- W2340148237 modified "2023-09-27" @default.
- W2340148237 title "Concepts of Programming Languages: A Unified Approach" @default.
- W2340148237 cites W121886698 @default.
- W2340148237 cites W131352529 @default.
- W2340148237 cites W144994574 @default.
- W2340148237 cites W1481862033 @default.
- W2340148237 cites W1484366641 @default.
- W2340148237 cites W1487410109 @default.
- W2340148237 cites W1491178396 @default.
- W2340148237 cites W1494199306 @default.
- W2340148237 cites W1503399292 @default.
- W2340148237 cites W1505718642 @default.
- W2340148237 cites W1507693023 @default.
- W2340148237 cites W1509843845 @default.
- W2340148237 cites W1511703676 @default.
- W2340148237 cites W1514258760 @default.
- W2340148237 cites W1523047387 @default.
- W2340148237 cites W1533109738 @default.
- W2340148237 cites W1537618227 @default.
- W2340148237 cites W1541318173 @default.
- W2340148237 cites W1544633123 @default.
- W2340148237 cites W1546657258 @default.
- W2340148237 cites W1551518726 @default.
- W2340148237 cites W1554859476 @default.
- W2340148237 cites W1555412307 @default.
- W2340148237 cites W1557561422 @default.
- W2340148237 cites W1562714622 @default.
- W2340148237 cites W1567612444 @default.
- W2340148237 cites W1567918249 @default.
- W2340148237 cites W1569289170 @default.
- W2340148237 cites W1570058570 @default.
- W2340148237 cites W1577171536 @default.
- W2340148237 cites W1579401073 @default.
- W2340148237 cites W1582924718 @default.
- W2340148237 cites W1585022015 @default.
- W2340148237 cites W1590937195 @default.
- W2340148237 cites W1595713800 @default.
- W2340148237 cites W1644882639 @default.
- W2340148237 cites W1649464997 @default.
- W2340148237 cites W17319743 @default.
- W2340148237 cites W176210955 @default.
- W2340148237 cites W1766332311 @default.
- W2340148237 cites W1770006921 @default.
- W2340148237 cites W1783388813 @default.
- W2340148237 cites W1809844233 @default.
- W2340148237 cites W1829244603 @default.
- W2340148237 cites W194677851 @default.
- W2340148237 cites W1967919960 @default.
- W2340148237 cites W1969456304 @default.
- W2340148237 cites W1971418649 @default.
- W2340148237 cites W1998555378 @default.
- W2340148237 cites W1998875295 @default.
- W2340148237 cites W2000050212 @default.
- W2340148237 cites W2002301065 @default.
- W2340148237 cites W2003507527 @default.
- W2340148237 cites W2004158097 @default.
- W2340148237 cites W2005973420 @default.
- W2340148237 cites W2011398297 @default.
- W2340148237 cites W2012301138 @default.
- W2340148237 cites W2019376542 @default.
- W2340148237 cites W2027657506 @default.
- W2340148237 cites W2039820890 @default.
- W2340148237 cites W2040046786 @default.
- W2340148237 cites W2040713190 @default.
- W2340148237 cites W2044758536 @default.
- W2340148237 cites W2049583580 @default.
- W2340148237 cites W2056958905 @default.
- W2340148237 cites W2061209360 @default.
- W2340148237 cites W2071136304 @default.
- W2340148237 cites W2071174987 @default.
- W2340148237 cites W2073544767 @default.
- W2340148237 cites W2078235355 @default.
- W2340148237 cites W2082569622 @default.
- W2340148237 cites W2084788336 @default.
- W2340148237 cites W2089674328 @default.
- W2340148237 cites W2093415968 @default.
- W2340148237 cites W2094631165 @default.
- W2340148237 cites W2095224573 @default.
- W2340148237 cites W2100738443 @default.
- W2340148237 cites W2104416102 @default.
- W2340148237 cites W2105045857 @default.
- W2340148237 cites W2105232714 @default.
- W2340148237 cites W2106192381 @default.
- W2340148237 cites W2111304450 @default.
- W2340148237 cites W2112774031 @default.
- W2340148237 cites W2123596219 @default.
- W2340148237 cites W2124479173 @default.
- W2340148237 cites W2133472914 @default.
- W2340148237 cites W2138387375 @default.
- W2340148237 cites W2151384546 @default.
- W2340148237 cites W2154273644 @default.
- W2340148237 cites W2159709550 @default.
- W2340148237 cites W2166822586 @default.
- W2340148237 cites W2171727886 @default.
- W2340148237 cites W2172307690 @default.
- W2340148237 cites W2173093539 @default.