Showing posts with label encapsulation. Show all posts
Showing posts with label encapsulation. Show all posts

14 January 2025

🧭Business Intelligence: Perspectives (Part XXII: Queries' Complexity)

Business Intelligence Series
Business Intelligence Series

Independently whether standalone or encapsulated in database objects, the queries written can become complex in time, respectively difficult to comprehend and maintain. One can reduce the cognitive load by identifying the aspects that enable one’s intuition - order, similarity and origin being probably the most important aspects that help coping with the inherent complexity. 

One should start with the table having the lowest level of detail, usually a transaction table that forms the backbone of a certain feature. For example, for Purchase Orders this could be upon case the distribution or line level. If Invoices are added to the logic, and there could be multiple invoice line for a record from the former logic, then this becomes the new level of detail. Further on, if General Ledger lines are added, more likely this becomes the lowest level of detail, and so on.

This approach allows to keep a consistent way of building the queries while enabling to validate the record count, making sure that no duplicates are added to the logic. Conversely, one can start also from the table with the lowest level of details, and add tables successively based on their level of detail, though the database engine may generate upon case a suboptimal plan. In addition, checking the cardinality may involve writing a second query. 

One should try to keep the tables belonging to the same entity together, when possible (e.g. Purchase Order vs. Vendor information). This approach allows to reduce the volume of work required to manage, review, test and understand the query later. If the blocks are too big, then occasionally it makes sense to bring pieces of logic into CTEs (Common Table Expressions), or much better into views that allow to better encapsulate and partition the logic.

CTEs allow to split the logic into logical steps, allowing occasionally to troubleshoot the logic on pieces though one should keep a balance between maintainability and detail. In extremis, people may create unnecessarily an additional CTE for each join. The longer and the more fragmented a query, the more difficult it becomes to troubleshoot and even understand. Readability can be better achieved though indentation, by keeping things together that belong together, respectively partitioning the logic in logical blocks that derive from the model. 

Keeping things together should be applied also to the other elements. For example, the join constraints should be limited only to the fields participating in the join (and, if possible, all the other constraints should be brought in the WHERE clause). Bringing the join constraints in the WHERE clause, an approach used in the past, decreases query readability no matter how well the WHERE clause is structured, and occasionally can lead to constraints’ duplication or worse, to missing pieces of logic. 

The order of the attributes should follow a logic that makes sense. One approach is to start from the tables with lowest cardinality that identify entities uniquely and move to the attributes that have a higher level of detail. However, not all attributes are equally important, and thus one might have to compromise and create multiple groups of data coming from different levels. 

One should keep in mind that the more random the order of the attributes is, the more difficult it becomes to validate the data as one needs to jump multiple times either in the query or in the mask. Ideally one should find a balance between the two perspectives. Having an intuitive logic of how the attributes are listed increases queries’ readability, maintainability and troubleshooting. The more random attributes’ listing, the higher the effort for the same. 

Previous Post  <<||>>   Next Post

30 December 2007

🏗️Software Engineering: Encapsulation (Just the Quotes)

"Object-oriented programming languages support encapsulation, thereby improving the ability of software to be reused, refined, tested, maintained, and extended. The full benefit of this support can only be realized if encapsulation is maximized during the design process. […] design practices which take a data-driven approach fail to maximize encapsulation because they focus too quickly on the implementation of objects." (Rebecca Wirfs-Brock, "Object-oriented Design: A. responsibility-driven approach", 1989)

"Object-oriented programming increases the value of these metrics by managing this complexity. The most effective tool available for dealing with complexity is abstraction. Many types of abstraction can be used, but encapsulation is the main form of abstraction by which complexity is managed in object-oriented programming. Programming in an object-oriented language, however, does not ensure that the complexity of an application will be well encapsulated. Applying good programming techniques can improve encapsulation, but the full benefit of object-oriented programming can be realized only if encapsulation is a recognized goal of the design process." (Rebecca Wirfs-Brock," Object-Oriented Design: A responsibility-driven approach", 1989)

"Programming in an object-oriented language, however, does not ensure that the complexity of an application will be well encapsulated. Applying good programming techniques can improve encapsulation, but the full benefit of object-oriented programming can be realized only if encapsulation is a recognized goal of the design process." (Rebecca Wirfs-Brock, "Object-oriented Design: A responsibility-driven approach", 1989)

"[...] encapsulation - also known as information hiding - prevents clients from seeing its inside view, were the behavior of the abstraction is implemented." (Grady Booch, "Object-Oriented Design With Applications", 1991)

"Encapsulation says that, not only are you allowed to take a simpler view of a complex concept, you are not allowed to look at any of the details of the complex concept. What you see is what you get - it's all you get!" (Steve C McConnell," Code Complete: A Practical Handbook of Software Construction", 1993)

"The concept of modularity is related to information hiding, encapsulation, and other design heuristics. But sometimes thinking about how to assemble a system from a set of black boxes provides insights that information hiding and encapsulation don't, so the concept is worth having in your back pocket." (Steve C McConnell," Code Complete: A Practical Handbook of Software Construction", 1993)

"Watch for coupling that's too tight. 'Coupling' refers to how tight the connection is between two classes. In general, the looser the connection, the better. Several general guidelines flow from this concept: Minimize accessibility of classes and members. Avoid friend classes, because they're tightly coupled. Make data private rather than protected in a base class to make derived classes less tightly coupled to the base class. Avoid exposing member data in a class's public interface. Be wary of semantic violations of encapsulation. Observe the 'Law of Demeter' [...]. Coupling goes hand in glove with abstraction and encapsulation. Tight coupling occurs when an abstraction is leaky, or when encapsulation is broken." (Steve C McConnell," Code Complete: A Practical Handbook of Software Construction", 1993)

"Encapsulation picks up where abstraction leaves off. Abstraction says, ‘You're allowed to look at an object at a high level of detail’. Encapsulation says, ‘Furthermore, you aren't allowed to look at an object at any other level of detail’." (Steve C McConnell, "Code Complete: A Practical Handbook of Software Construction" 2nd Ed., 2004)

"Making domain concepts explicit in your code means other programmers can gather the intent of the code much more easily than by trying to retrofit an algorithm into what they understand about a domain. It also means that when the domain model evolves - which it will, as your understanding of the domain grows - you are in a good position to evolve the code. Coupled with good encapsulation, the chances are good that the rule will exist in only one place, and that you can change it without any of the dependent code being any the wiser." (Dan North [in Kevlin Henney’s "97 Things Every Programmer Should Know", 2010]) 

"More generally, each unit of code, from a block to a library, should have a narrow interface. Less communication reduces the reasoning required. This means that getters that return internal state are a liability - don’t ask an object for information to work with. Instead, ask the object to do the work with the information it already has. In other words, encapsulation is all - and only - about narrow interfaces." (Yechiel Kimchi [in Kevlin Henney’s "97 Things Every Programmer Should Know", 2010])

"The primary intent behind the principle of encapsulation is to separate the interface and the implementation, which enables the two to change nearly independently. This separation of concerns allows the implementation details to be hidden from the clients who must depend only on the interface of the abstraction. If an abstraction exposes implementation details to the clients, it leads to undesirable coupling between the abstraction and its clients, which will impact the clients whenever the abstraction needs to change its implementation details. Providing more access than required can expose implementation details to the clients, thereby, violating the 'principle of hiding'." (Girish Suryanarayana et al, "Refactoring for Software Design Smells: Managing Technical Debt", 2015)

"The principle of encapsulation advocates separation of concerns and information hiding through techniques such as hiding implementation details of abstractions and hiding variations." (Girish Suryanarayana et al, "Refactoring for Software Design Smells: Managing Technical Debt", 2015)

20 January 2007

🌁Software Engineering: Data/Information Hiding (Definitions)

"In programming, the practice of locating some parts of the system in software structures that are invisible (inaccessible) to others. Usually, the information so hidden includes details that the programmer considers inessential and those aspects of the system that result from design decisions that are somehow difficult or likely to change. Compare with abstraction, which is a category of techniques by which one can make decisions about what information to hide." (Bill Pribyl & Steven Feuerstein, "Learning Oracle PL/SQL", 2001)

"Hiding the state of a class in private member variables." (Jesse Liberty, "Sams Teach Yourself C++ in 24 Hours" 3rd Ed., 2001)

"The ability of an object to hide its members from other parts of a program to protect those members from accidental change." (Greg Perry, "Sams Teach Yourself Beginning Programming in 24 Hours" 2nd Ed., 2001)

"The ability of a class to hide the details about how it works from outside code." (Rod Stephens, "Start Here! Fundamentals of Microsoft .NET Programming", 2011)

"The practice of hiding the details of a module with the goal of controlling access to the details of the module" (Nell Dale & John Lewis, "Computer Science Illuminated" 6th Ed., 2015)

"Use of segregation in design decisions to protect software components from negatively interacting with each other. Commonly enforced through strict interfaces." (Adam Gordon, "Official (ISC)2 Guide to the CISSP CBK" 4th Ed., 2015)

"The practice of hiding details within a module with the goal of controlling access to the details from the rest of the system" (Nell Dale et al, "Object-Oriented Data Structures Using Java" 4th Ed., 2016)

"The dependability concept of not allowing functions access to data structures unless they are specifically designated to do so in the context of a module or object." (O Sami Saydjari, "Engineering Trustworthy Systems: Get Cybersecurity Design Right the First Time", 2018)

"Concealing the structure of some (potentially unstable) parts of a program behind a stable interface." (Karl Beecher, "Computational Thinking - A beginner's guide to problem-solving and programming", 2017)

"The intentional denial of access to operate directly on data without going through specified encapsulating procedures, which operate on the data in a well-controlled manner. See encapsulation." (O Sami Saydjari, "Engineering Trustworthy Systems: Get Cybersecurity Design Right the First Time", 2018)

02 February 2006

OOP: Encapsulation (Definitions)

"It is a simple, yet reasonable effective, system-building tool. It allows suppliers to present cleanly specified interfaces around the services they provide. A consumer has full visibility to the procedures offered by an object, and no visibility to its data. From a consumer's point of view, and object is a seamless capsule that offers a number of services, with no visibility as to how these services are implemented [...] technical term for this is encapsulation." (Brad J Cox, "Object Oriented Programming: An Evolutionary Approach", 1986)

A software development technique that consists of isolating a system function or a set of data and operations on those data within a module and providing precise specifications for the module. (IEEE," IEEE Standard Glossary of Software Engineering Terminology", 1990)

"The concept of encapsulation as used in an object-oriented context is not essentially different from its dictionary definition. It still refers to building a capsule, in the case a conceptual barrier, around some collection of things." (Rebecca Wirfs-Brock et al, "Designing Object-Oriented Software", 1990]

"Encapsulation or equivalently information hiding refers to the practice of including within an object everything it needs, and furthermore doing this in such a way that no other object need ever be aware of this internal structure." (Ian Graham, "Object-Oriented Methods", 1991]

"Data hiding is sometimes called encapsulation because the data and its code are put together in a package or 'capsule.'" (David N Smith, "Concepts of Object-Oriented Programming", 1991)

"Encapsulation is used as a generic term for techniques which realize data abstraction. Encapsulation therefore implies the provision of mechanisms to support both modularity and information hiding. There is therefore a one to one correspondence in this case between the technique of encapsulation and the principle of data abstraction." (Gordon Blair et al, "Object-Oriented Languages, Systems and Applications", 1991)

"Encapsulation (also information hiding) consists of separating the external aspects of an object which are accessible to other objects, from the internal implementation details of the object, which are hidden from other objects." (James Rumbaugh et al, "Object-Oriented Modeling and Design", 1991)

"[...] encapsulation - also known as information hiding - prevents clients from seeing its inside view, were the behavior of the abstraction is implemented." (Grady Booch, "Object-Oriented Design With Applications", 1991)

"We say that the changeable, hidden information becomes the secret of the module; also, according to a widely used jargon, we say that such information is encapsulated within the implementation." (Carlo Ghezzi et al, "Fundamentals of Software Engineering", 1991]

"As a process, encapsulation means the act of enclosing one or more items within a (physical or logical) container. Encapsulation, as an entity, refers to a package or an enclosure that holds (contains, encloses) one or more items. It is extremely important to note that nothing is said about 'the walls of the enclosure'. Specifically, they may be 'transparent', 'translucent', or even 'opaque'." Compare with information hiding, which implies invisibility." (Bill Pribyl & Steven Feuerstein, "Learning Oracle PL/SQL", 2001)

"Encasing information and behavior within an object so that its structure and implementation are hidden to other objects that interact with it." (Marcus Green & Bill Brogden, "Java 2 Programmer Exam Cram 2 (Exam CX-310-035)", 2003)

"A mechanism used to hide the data, internal structure, and implementation details of some element, such as an object or subsystem. All interaction with an object is through a public interface of operations." (Craig Larman, "Applying UML and Patterns", 2004)

"An object-oriented technique that may hide, or abstract, the inner workings of an object and expose only the relevant characteristics and operations on the object to other objects." (Bob Bryla, "Oracle Database Foundations", 2004)

"Restricting the visibility of members of a type so they are not visible to clients of the type when they shouldn’t be. This is a way of exposing only the abstraction supported by the type, while hiding implementation details, which prevents unwanted access to them from clients and keeps the abstraction exposed by the type consistent and minimal." (Dean Wampler & Alex Payne, "Programming Scala", 2009)

"In object-oriented design, the principle that it should be possible to refer to an object with behavior and not know anything about how that behavior is implemented." (David C Hay, "Data Model Patterns: A Metadata Map", 2010)

"Detail hiding. A class hides its internal details so the rest of the program doesn't need to understand how they work, just how to use them." (Rod Stephens, "Stephens' Visual Basic® Programming 24-Hour Trainer", 2011)

"(1) A language mechanism for restricting access to some of an object’s components. (2) A language construct that facilitates the bundling of data with methods (or other functions) operating on that data." (Craig S Mullins, "Database Administration: The Complete Guide to DBA Practices and Procedures", 2012)

"The veil of abstraction separating the interface from the implementation (whether enforced or not), which mandates that all access to an object’s state be through methods alone." (Jon Orwant et al, "Programming Perl" 4th Ed., 2012)

"A language feature that enforces information hiding; bundling data and actions so that the logical properties of data and actions are separated from the implementation details" (Nell Dale & John Lewis, "Computer Science Illuminated" 6th Ed., 2015)

"The bundling of data with the procedures that operate on that data, such that data may only be changed by those procedures - a technique for reducing program complexity." (O Sami Saydjari, "Engineering Trustworthy Systems", 2018)

"The object-oriented programming technique of limiting the exposure of variables and methods to simplify the API of a class or package. Using the private and protected keywords, a programmer can limit the exposure of internal ('black box') parts of a class. Encapsulation reduces bugs and promotes reusability and modularity of classes. This technique is also known as data hiding." (Daniel Leuck et al, "Learning Java" 5th Ed., 2020)

07 January 2006

OOP: Interface (Definitions)

"A contract that specifies the members a class or struct can implement to receive generic services for that type." (Jesse Liberty, "Programming C#" 2nd Ed., 2002)

"In Java, an interface is similar to a class definition, except that no detailed implementation of methods is provided. A class that implements an interface must provide the code to implement the methods. You can think of an interface as defining a contract between the calling method and the class that implements the interface." (Marcus Green & Bill Brogden, "Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035)", 2003)

"A set of signatures of public operations." (Craig Larman, "Applying UML and Patterns", 2004)

"A defined set of properties, methods, and collections that form a logical grouping of behaviors and data. Classes are defined by the interfaces that they implement. An interface can be implemented by many different classes." (Jim Joseph et al, "Microsoft SQL Server 2008 Reporting Services Unleashed", 2009)

"The specification of the means by which services can be invoked and data can be manipulated across an encapsulation boundary (e.g., class)." (Bruce P Douglass, "Real-Time Agility", 2009)

"The externally visible definition of the operations permitted on an application component." (David Lyle & John G Schmidt, "Lean Integration", 2010)

"Defines a set of members that a class can provide." (Rod Stephens, "Start Here! Fundamentals of Microsoft .NET Programming", 2011)

"Defines public properties, methods, and events that a class must provide to satisfy the interface." (Rod Stephens, "Stephens' Visual Basic Programming 24-Hour Trainer", 2011)

"A defined set of properties, methods, and collections that form a logical grouping of behaviors and data." (Microsoft, "SQL Server 2012 Glossary", 2012)

"The services a piece of code promises to provide forever, in contrast to its implementation, which it should feel free to change whenever it likes." (Jon Orwant et al, "Programming Perl" 4th Ed., 2012)

"A keyword used to declare an interface." (Daniel Leuck et al, "Learning Java" 5th Ed., 2020)

Related Posts Plugin for WordPress, Blogger...

About Me

My photo
Koeln, NRW, Germany
IT Professional with more than 24 years experience in IT in the area of full life-cycle of Web/Desktop/Database Applications Development, Software Engineering, Consultancy, Data Management, Data Quality, Data Migrations, Reporting, ERP implementations & support, Team/Project/IT Management, etc.