`
wangyonghe
  • 浏览: 43289 次
社区版块
存档分类
最新评论

Coding Principle

阅读更多

编码模式

1、简介

      下列模式是我在编码的过程中发现的,它们可以帮助程序员编写出高质量的代码,本文会不断的更新,如果网友们也发现了好的模式,可以回复,也可以留言给我,我会将好的模式加在里面并注明出处。

2、编码模式

(1) 方法参数具体化模式(模式名称暂定):

    我们在设计类方法的时候,经常需要传入一些参数来改变方法的运行结果,如果我们对参数的定义很泛,例如:使用Integer、String 等通用的类型作为参数,就会使方法调用都变迷惑,因为他们不知道方法内到底需要什么样的字符串或整形(通过注释的形式不能显式的约束使用者)。缺点有:1)方法内部实现要对参数进行很多有效性判断;2)很多问题不能够在编译器发现。Sun 公司在JDK5.0 定义了Enum 类型,建议用户不要直接使用Integer 来作为常量,就是因为Integer 类型太泛;如果从面向对象的角度来分析,也不应该将某个业务对象的内部细节暴露出来。所以我们在定义方法时尽量避免使用很泛的类型作为参数,而应该使用具体化的参数,注意:这里的具体化并不是指使用具体的Class,一般情况下应该使用Interface。

    注意:在一些特殊情况下,使用很泛的类型作为参数是不可避免的,所以本原则也不是决对的,要视情况而定,软件设计中的很多原则都不是决对的。

分享到:
评论

相关推荐

    Channel Coding in Communication Networks

    1.3.1. Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.3.2. Measurement of self-information . . . . . . . . . . . . . . . . . . . . 10 1.3.3. Entropy of a source. ....

    IMAGE and VIDEO COMPRESSION for MULTIMEDIA ENGINEERING Fundamentals, Algorithms, and Standards.part1.rar

    2000 8.4 Summary 8.5 Exercises References Chapter 9 Nonstandard Image Coding 9.1 Introduction 9.2 Vector Quantization 9.2.1 Basic Principle of Vector Quantization 9.2.2 ...

    SOLID Principles Succinctly

    There is always room for improving one’s coding ability, and SOLID design principles offer one way to see marked improvements in final output. With SOLID Principles Succinctly, author Gaurav Kumar ...

    Perceptual Rate Distortion Optimization for VideoCoding Using Free-Energy Principle

    从提供的文件内容中可以看出,这篇文章主要讨论了基于自由能原理的视频编码感知率失真优化(Perceptual Rate Distortion Optimization for Video Coding using Free-Energy Principle)。文章中提到了一个称为FEJND...

    Information Theory and Statistics A Tutorial

    This tutorial is concerned with ...introduction is provided to the theory of universal coding, and to statistical inference via the minimum description length principle motivated by that theory.

    信息论基础(英文版)

    14.13 Minimum Description Length Principle 500 Summary 501 Problems 503 Historical Notes 507 15 Network Information Theory 509 15.1 Gaussian Multiple-User Channels 513 CONTENTS xi 15.1.1 Single-User ...

    Python 3 Object-Oriented Programming(PACKT,2ed,2015)

    Coding in Python minimizes development time and increases productivity in comparison to other languages. Clean, maintainable code is easy to both read and write using Python's clear, concise syntax. ...

    Radar Signals

    This book is comprised of 14 chapters and begins with an overview of the concepts and techniques of pulse compression matched filtering, with emphasis on coding source and decoding device. The ...

    TMS320C6748_PCB_创龙底板图

    说明地址:http://www.pudn.com/Download/item/id/3829451.html;; 创龙底板原理图,dsp编码时引脚查看对比,C6748+fpga (Principle of Chuanglong Floor, Pin View and Contrast in DSP Coding, C6748+fpga)

    Less.Web.Development.Essentials.2nd.Edition

    Meet the DRY (Don't Repeat Yourself) principle of software coding for your web development projects by avoiding code duplication Shorten the debugging time of complex CSS code with Less for specific ...

    Practical Database Programming with Java

    The various actual JDBC APIs and JDBC drivers are discussed and presented with real example coding explanations. The working structure and principle of using a JDBC driver to establish a valid ...

    MIMO-OFDM Wireless Communications with MATLAB

    4.2 Basic Principle of OFDM 121 4.2.1 OFDM Modulation and Demodulation 121 4.2.2 OFDM Guard Interval 126 4.2.3 OFDM Guard Band 132 4.2.4 BER of OFDM Scheme 136 4.2.5 Water-Filling Algorithm for ...

    Data_Compression+The+Complete+Reference+4th+edition

    #### 5.3 不确定性原理(The Uncertainty Principle) 介绍不确定性原理及其对图像压缩的影响。 #### 5.4 傅里叶图像压缩(Fourier Image Compression) 讨论傅里叶变换在图像压缩中的具体应用。 #### 5.5 CWT及其...

    cours_optimal_control_

    基础教程通常会讲解如 Pontryagin's Maximum Principle(庞特里亚金最大值原理)这样的关键工具,它是解决连续时间最优控制问题的主要方法之一。 最优控制在各个领域都有广泛的应用,如航空航天、自动控制、机器人...

Global site tag (gtag.js) - Google Analytics