`

Data abstraction - universal/dynamic data structure

    博客分类:
  • OO*
阅读更多
Recently, I read two articles about data holders, search the key word 元数据、开放数据模型及动态系统. The scenario is that constantly we need to change the data fields, e.g., add/delete some fields. This task is tedious because usually we need to update a database table, and then add fields in all corresponding classes. The repeated steps make people think whether there is a better way. A remedy is to hold all data in key-value pairs(in a Map) throughout the system, then whenever we need a new field, just add a new key value pair to the Map and extract it whenever we needed. This is a meta level idea, similar ideas have been around for at least last 6 years, though the implementation vary.

Before we dive in, let's pull back to take a bird view on the problem to get all the aspects of the problem. The better we understand the problem, the better a solution we could find. If we look at the tedious way to change a data field, the whole process is based on two facts:

  1. In JAVA every field is strong typed. When we get/set the new data field, we have to have to some kinds of getter/setter method first.
  2. POJO are static, not dynamic like Collection classes. So every data field change requires code changes. This means the data structure in POJO is static.

In order to fix the first problem, there are two common ways. One is to use a Map and create a universal get(key) method. The other is to make the field public, then you can use dot operation.

In order to fix the second problem, a natural way is to use Collection classes.

So the Collection classes fix both #1 and #2. But are there any downsides? Well, depends. Consider the following scenarios:

  • Collection classes are not strong typed, so any object you get from it is of type Object. If we want to call something not in the Object class, we have to cast it to a particular class. So we will have quite some instancof checks and class castings. While class casting doesn't cost too much in performance, instanceof does. One way to fix this is through meta data, i.e., we save the type somewhere. However, when we are in the maintenance mode, there is no way we can track where a property is used because every property's access is through the same get(key) method. This present a hard roadblock when refactoring, and possibly is a flag for over-abstraction.
  • Use Collections in the interfaces. This could cause major integration time and troubleshooting/debug time because both sides of the interface need to agree upon the runtime data(data present or missing, or the data format issue, besides the data value issue). Though this is one of the major reasons why we want to choose Collection classes, in my experience it takes more time later on than the time we save earlier during coding.
  • Performance degrade when we simultanuously have large number of operations on insert/update/delete/retrieve.  Most of the Collection classes work fast only on certain operations and slow on other operations, but not fast on all operations. This fact makes it hard to build a universal data structure.

I just listed the cases that I am aware of, there could be other drawbacks. So we should use this approach only when we can bypass these problems, somehow. For example, in a simple db-to-web applications, we just get data from db and display on web pages. In this case, we don't care the types of fields, just use the toString() method to the output; there are few interfaces(maybe just a DAO); and we just retrieve them once and loop through.

In mid-level complex applications, however, we could have all 3 of the above scenarios and it's unlikely that the Collection classes would fit the need for maintenance and performance reasons.
分享到:
评论

相关推荐

    Data-Abstraction-and-Problem-Solving-with-Java_co_data abstracti

    《数据抽象与问题解决——Java实现》是一本深入探讨如何使用Java进行数据抽象和问题解决的书籍。在编程领域,数据抽象是核心概念之一,它允许我们构建复杂系统时忽略不必要的细节,专注于关键特征,而问题解决则是...

    PyPI 官网下载 | midi-abstraction-0.9.2.tar.gz

    《PyPI官网下载:midi-abstraction-0.9.2.tar.gz——探索Python音乐处理库》 在Python的世界里,PyPI(Python Package Index)是一个不可或缺的资源库,它为开发者提供了海量的开源软件包,方便他们进行项目开发。...

    PyPI 官网下载 | midi-abstraction-0.8.8.tar.gz

    《PyPI上的midi-abstraction-0.8.8.tar.gz:深入解析Python MIDI抽象库》 在Python编程领域,PyPI(Python Package Index)是广大开发者寻找和分享Python库的重要平台。今天我们要关注的是其中的一个名为"midi-...

    PyPI 官网下载 | mq_client_abstraction-0.0.32.tar.gz

    《PyPI官网下载:mq_client_abstraction-0.0.32.tar.gz——探索Python的分布式消息队列抽象层》 PyPI(Python Package Index)是Python开发者们分享和获取软件包的重要平台,其中的“mq_client_abstraction-0.0.32....

    Python库 | mq_client_abstraction-0.0.14.tar.gz

    《Python库解析:mq_client_abstraction-0.0.14》 在IT行业中,Python以其简洁、易读的语法和强大的库支持成为了开发者们钟爱的编程语言,尤其是在后端开发领域。本文将深入探讨名为`mq_client_abstraction`的...

    Abstraction-in-java.zip_in

    在`Abstraction-in-java.zip_in`这个压缩包中,我们可以看到多个与抽象相关的Java源代码文件,如Metaquery.java、InnerQuery.java等,这些文件可能属于某个数据查询或处理框架的一部分。 1. **抽象类与接口**: - ...

    PyPI 官网下载 | mq_client_abstraction-0.0.38.tar.gz

    《PyPI官网下载:mq_client_abstraction-0.0.38.tar.gz——探索Python库在分布式环境中的应用》 PyPI(Python Package Index)是Python开发者的重要资源库,它提供了大量的开源Python库,便于开发者们下载和使用。...

    Data Abstraction and Problem Solving with C++(6th) 无水印pdf

    Data Abstraction and Problem Solving with C++(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...

    PyPI 官网下载 | object_store_abstraction-0.2.9.tar.gz

    "object_store_abstraction-0.2.9.tar.gz" 是一个在PyPI上可下载的压缩包,它包含了名为 "object_store_abstraction" 的Python库的版本0.2.9。这个库的目标是提供一个抽象层来处理不同的对象存储服务,使开发者能够...

    tcg-mtm-mobile-abstraction-layer-1.0r2.03.pdf

    TCG Mobile Abstraction Layer(MAL)是 TCG 在 mobile 领域的技术规范,旨在为移动设备提供一个通用的安全接口,保护用户的隐私和敏感数据。 TCG MAL 在 mobile 领域的技术规范主要目标是提供一个通用的安全接口,...

    aws-abstraction-framework-0.1.0-sources.jar

    官方版本,亲测可用

    aws-abstraction-framework-0.1.0.jar

    官方版本,亲测可用

    DeepLearningTutorials

    multiple levels of representation and abstraction that help to make sense of data such as images, sound, and text. The tutorials presented here will introduce you to some of the most important deep ...

    spring-data-commons-1.2.0.M2.zip

    Spring Data Commons 提供了一套通用的基础设施,用于构建基于 Spring 的数据访问应用程序。这个库的核心功能包括: 1. **Repository Abstraction**:提供了一个接口层,开发者可以自定义接口来定义数据访问行为,...

    PostGIS源代码安装指南

    - **说明**:GDAL (Geospatial Data Abstraction Library) 是一种广泛使用的开源数据模型,用于读取、写入以及处理大量的地理空间数据集。它为PostGIS提供了对多种地理数据格式的支持。 #### 编译安装 json-c,添加...

    [PDF] Fundamentals of Data Structure in C

    Data structure + Algorithm = Programming The tools and techniques to design and implement large-scale computer systems: Data abstraction Algorithm specification Performance analysis Performance ...

    系统修复命令 windowsxp系统修复命令.doc

    - Windows Hardware Abstraction Layer (HAL) - 损坏的注册表文件(\WINDOWS\SYSTEM32\CONFIG\) - 不正确的BOOT.INI文件 - 损坏的NTOSKRNL.EXE文件 - 缺失的NTLDR文件 2. **使用SFC命令修复系统文件**: - ...

    image-search-abstraction-layer:小型NODE.JS后端API,它利用imgur的图像搜索API并收集搜索数据

    《构建基于NODE.JS的图搜抽象层:深入解析image-search-abstraction-layer项目》 在当前信息化社会,图像搜索引擎已经成为我们获取视觉信息的重要途径。image-search-abstraction-layer项目,作为一个小型的NODE.JS...

    libgtk3-abstraction-generator:该项目用于围绕libgtk3生成Kotlin抽象

    标题中的“libgtk3-abstraction-generator”是一个工具,它的主要目标是为libgtk3库创建Kotlin语言的抽象层。libgtk3是一个流行的图形用户界面(GUI)库,主要用于开发跨平台的应用程序,特别是针对Linux操作系统。...

    data structure

    《Data Abstraction & Problem Solving with C++》是Frank M. Carrano和Timothy Henry所著的一本关于数据结构与算法的教材,第六版由Pearson Education出版。该书针对C++编程语言进行了深入探讨,并结合数据抽象和...

Global site tag (gtag.js) - Google Analytics