Mock Trainwreck
   HOME





Mock Trainwreck
In computer science, the term Mock Trainwreck refers to the difficulty of mocking a deeply nested model structure. Mocking is the creation of mock objects which can be used to mimic the behavior of real objects, often because it is hard to test with the real objects. A trainwreck is multiple levels of method calls (called a chain), which each return objects upon which new methods can be called. Deeply nested models go against the Law of Demeter because the property's property must be accessed. The Law of Demeter, also known as the principle of least knowledge is a design guideline to promote loose coupling of data structures that are not closely related, and thus should probably not be coupled together. In addition, this level of coupling can be considered an inappropriate intimacy code smell. Mock trainwrecks should be avoided when possible. This is because not only does it makes it harder to test the code which uses them, but also because they are harder to work with from a de ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


picture info

Computer Science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, applied disciplines (including the design and implementation of Computer architecture, hardware and Software engineering, software). Algorithms and data structures are central to computer science. The theory of computation concerns abstract models of computation and general classes of computational problem, problems that can be solved using them. The fields of cryptography and computer security involve studying the means for secure communication and preventing security vulnerabilities. Computer graphics (computer science), Computer graphics and computational geometry address the generation of images. Programming language theory considers different ways to describe computational processes, and database theory concerns the management of re ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Mock Object
In computer science, a mock object is an object that imitates a production object in limited ways. A programmer might use a mock object as a test double for software testing. A mock object can also be used in generic programming. Analogy A mock object can be useful to the software tester like a car designer uses a crash test dummy to simulate a human in a vehicle impact. Motivation In a unit test, mock objects can simulate the behavior of complex, real objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test. If an object has any of the following characteristics, it may be useful to use a mock object in its place: * it supplies non-deterministic results (e.g. the current time or the current temperature) * it has states that are difficult to create or reproduce (e.g. a network error) * it is slow (e.g. a complete database, which would have to be prepared before the test) * it does not yet exist or may change behavior ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Law Of Demeter
The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs. In its general form, the LoD is a specific case of loose coupling. The guideline was proposed by Ian Holland at Northeastern University towards the end of 1987, and the following three recommendations serve as a succinct summary: # Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. # Each unit should only talk to its friends; don't talk to strangers. # Only talk to your immediate friends. The fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else (including its subcomponents), in accordance with the principle of "information hiding". It may be viewed as a corollary to the principle of least privilege, which dictates that a module possess only the information and resources necessary for its legitimate purpos ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


picture info

Coupling (computer Programming)
A coupling is a device used to connect two shafts together at their ends for the purpose of transmitting power. The primary purpose of couplings is to join two pieces of rotating equipment while permitting some degree of misalignment or end movement or both. In a more general context, a coupling can also be a mechanical device that serves to connect the ends of adjacent parts or objects. Couplings do not normally allow disconnection of shafts during operation, however there are torque-limiting couplings which can slip or disconnect when some torque limit is exceeded. Selection, installation and maintenance of couplings can lead to reduced maintenance time and maintenance cost. Uses Shaft couplings are used in machinery for several purposes. A primary function is to transfer power from one end to another end (ex: motor transfer power to pump through coupling). Other common uses: * To alter the vibration characteristics of rotating units * To connect the driving and the driven ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Code Smell
In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem. Determining what is and is not a code smell is subjective, and varies by language, developer, and development methodology. The term was popularized by Kent Beck on WardsWiki in the late 1990s. Usage of the term increased after it was featured in the 1999 book ''Refactoring: Improving the Design of Existing Code'' by Martin Fowler. It is also a term used by agile programmers. Definition One way to look at smells is with respect to principles and quality: "Smells are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality". Code smells are usually not bugs; they are not technically incorrect and do not prevent the program from functioning. Instead, they indicate weaknesses in design that may slow down development or increase the risk of bugs or failures in the future. Bad code ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


picture info

Dependency Injection
In software engineering, dependency injection is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. The pattern ensures that an object or function that wants to use a given service should not have to know how to construct those services. Instead, the receiving " client" (object or function) is provided with its dependencies by external code (an "injector"), which it is not aware of. Dependency injection makes implicit dependencies explicit and helps solve the following problems: * How can a class be independent from the creation of the objects it depends on? * How can an application, and the objects it uses support different configurations? Dependency injection is often used to keep code in-line with the dependency inversion principle. In statically ty ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  




Duck Typing
In computer programming, duck typing is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine whether an object can be used for a particular purpose. With nominative typing, an object is of a given type if it is declared as such (or if a type's association with the object is inferred through mechanisms such as object inheritance). With duck typing, an object is of a given type if it has all methods and properties required by that type. Duck typing may be viewed as a usage-based structural equivalence between a given object and the requirements of a type. Examples This simple example in Python 3 demonstrates how any object may be used in any context until it is used in a way that it does not support. class Duck: def swim(self): print("Duck swimming") def fly(self): print("Duck flying") class Whale: def swim(self): print("Whale swimming") for animal in uck(), ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]