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:
- 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.
- 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 - code1
资源来自pypi官网。 资源全名:midi-abstraction-0.9.2.tar.gz
资源来自pypi官网。 资源全名:midi-abstraction-0.8.8.tar.gz
python库。 资源全名:mq_client_abstraction-0.0.14.tar.gz
资源来自pypi官网。 资源全名:object_store_abstraction-0.2.9.tar.gz
资源来自pypi官网。 资源全名:mq_client_abstraction-0.0.38.tar.gz
资源来自pypi官网。 资源全名:mq_client_abstraction-0.0.32.tar.gz
Abstraction in java
官方版本,亲测可用
官方版本,亲测可用
TCG 在 mobile 领域的技术规范
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 ...
Data Abstraction and Problem Solving with C++(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...
Data Abstraction & Problem Solv - Frank M. Carrano.pdf
hadoop是什么? 初学hadoop需要哪些技术基础?...4.Functional Abstraction 5.Introduction to MapReduce 6.Hadoop Architecture 7.MapReduce Algorithms and Patterns 8.NOSQL Databases 9.Spark 不太完整 不好意思!
A novel abstraction-guided simulation approach using posterior probabilities for verification
This is a simple MySQL Abstraction Layer compatible with PHP 7+ that provides a simple and secure interaction with your database using mysqli_* functions at its core. This is perfect for small scale ...
Objects, Abstraction, Data Structures and Design - Using C++ 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源...
java-abstraction-inheritance:一个简单的Java控制台程序,使用抽象和继承的概念
Object-Orientation Abstraction and Data Structures Using Scala(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn...