Design Stuff




SOLID Principle for Object Oriented Design

SOLID Principle help you to not write frigile, regid and unresuable code

S	SRP		Single responsibility principle
			a class should have only a single responsibility (i.e. only one potential change in the software's specification should be able to affect the specification of the class)

O	OCP		Open/closed principle
			“software entities … should be open for extension, but closed for modification.”

L	LSP		Liskov substitution principle
			“objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.” See also design by contract.

I	ISP		Interface segregation principle
			“many client-specific interfaces are better than one general-purpose interface.”

D	DIP	 	Dependency inversion principle one should “depend upon abstractions, [not] concretions.”



REST Vs SOAP, The Difference Between Soap And Rest Someone asked me a question today “Why would anyone choose SOAP (Simple Object Access Protocol) instead of REST (Representational State Transfer)?” My response: “The general rule of thumb I’ve always heard is ‘Unless you have a definitive reason to use SOAP use REST’”. He asked “what’s one reason?” I thought about it for a minute and honestly answered that I haven’t ever come across a reason. My background is building great internet companies. While he seemed satisfied, I wasn’t very happy with that answer, I did some homework and here’s my summary on REST versus SOAP, the difference between SOAP and REST and why anyone would choose SOAP. As usual, with competing technologies both have value, the challenge is to know when to use each one (spoiler: luckily the answer is almost always REST). I’m clearly boiling down a somewhat so please don’t flame me for simplifying things, but feel free to provide any corrections you feel are necessary. Definitions REST RESTs sweet spot is when you are exposing a public API over the internet to handle CRUD operations on data. REST is focused on accessing named resources through a single consistent interface. SOAP SOAP brings it’s own protocol and focuses on exposing pieces of application logic (not data) as services. SOAP exposes operations. SOAP is focused on accessing named operations, each implement some business logic through different interfaces. Though SOAP is commonly referred to as “web services” this is a misnomer. SOAP has very little if anything to do with the Web. REST provides true “Web services” based on URIs and HTTP. By way of illustration here are few calls and their appropriate home with commentary. getUser(User); This is a rest operation as you are accessing a resource (data). switchCategory(User, OldCategory, NewCategory) This is a SOAP operation as you are performing an operation. Yes, either could be done in either SOAP or REST. The purpose is to illustrate the conceptual difference. Why REST? Here are a few reasons why REST is almost always the right answer. Since REST uses standard HTTP it is much simpler in just about ever way. Creating clients, developing APIs, the documentation is much easier to understand and there aren’t very many things that REST doesn’t do easier/better than SOAP. REST permits many different data formats where as SOAP only permits XML. While this may seem like it adds complexity to REST because you need to handle multiple formats, in my experience it has actually been quite beneficial. JSON usually is a better fit for data and parses much faster. REST allows better support for browser clients due to it’s support for JSON. REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached. It’s a bad argument (by authority), but it’s worth mentioning that Yahoo uses REST for all their services including Flickr and del.ici.ous. Amazon and Ebay provide both though Amazon’s internal usage is nearly all REST source. Google used to provide only SOAP for all their services, but in 2006 they deprecated in favor of REST source. It’s interesting how there has been an internal battle between rest vs soap at amazon. For the most part REST dominates their architecture for web services. Why SOAP? Here are a few reasons you may want to use SOAP. WS-Security While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. Supports identity through intermediaries, not just point to point (SSL). It also provides a standard implementation of data integrity and data privacy. Calling it “Enterprise” isn’t to say it’s more secure, it simply supports some security tools that typical internet services have no need for, in fact they are really only needed in a few “enterprise” scenarios. WS-AtomicTransaction Need ACID Transactions over a service, you’re going to need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant. Fortunately ACID transactions almost never make sense over the internet. REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can. Internet apps generally don’t need this level of transactional reliability, enterprise apps sometimes do. WS-ReliableMessaging Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries. Summary In Summary, SOAP is clearly useful, and important. For instance, if I was writing an iPhone application to interface with my bank I would definitely need to use SOAP. All three features above are required for banking transactions. For example, if I was transferring money from one account to the other, I would need to be certain that it completed. Retrying it could be catastrophic if it succeed the first time, but the response failed. SOAP vs REST Web Services There are many differences between SOAP and REST web services. The important 10 differences between SOAP and REST are given below: No. SOAP REST 1) SOAP is a protocol. REST is an architectural style. 2) SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer. 3) SOAP can't use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP. 4) SOAP uses services interfaces to expose the business logic. REST uses URI to expose business logic. 5) JAX-WS is the java API for SOAP web services. JAX-RS is the java API for RESTful web services. 6) SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP. 7) SOAP requires more bandwidth and resource than REST. REST requires less bandwidth and resource than SOAP. 8) SOAP defines its own security. RESTful web services inherits security measures from the underlying transport. 9) SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc. 10) SOAP is less preferred than REST. REST more preferred than SOAP.
UML 2.0 Class Diagrams
Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency These terms signify the relationships between classes. These are the building blocks of object oriented programming and very basic stuff. But still for some, these terms look like Latin and Greek. Just wanted to refresh these terms and explain in simpler terms. Association Association is a relationship between two objects. In other words, association defines the multiplicity between objects. You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects. Aggregation is a special form of association. Composition is a special form of aggregation. Example: A Student and a Faculty are having an association. Aggregation Aggregation is a special case of association. A directional association between objects. When an object ‘has-a’ another object, then you have got an aggregation between them. Direction between them specified which object contains the other object. Aggregation is also called a “Has-a” relationship. Composition Composition is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition. Example: A class contains students. A student cannot exist without a class. There exists composition between class and students. Difference between aggregation and composition Composition is more restrictive. When there is a composition between two objects, the composed object cannot exist without the other object. This restriction is not there in aggregation. Though one object can contain the other object, there is no condition that the composed object must exist. The existence of the composed object is entirely optional. In both aggregation and composition, direction is must. The direction specifies, which object contains the other object. Example: A Library contains students and books. Relationship between library and student is aggregation. Relationship between library and book is composition. A student can exist without a library and therefore it is aggregation. A book cannot exist without a library and therefore its a composition. For easy understanding I am picking this example. Don’t go deeper into example and justify relationships! Abstraction Abstraction is specifying the framework and hiding the implementation level information. Concreteness will be built on top of the abstraction. It gives you a blueprint to follow to while implementing the details. Abstraction reduces the complexity by hiding low level details. Example: A wire frame model of a car. Generalization Generalization uses a “is-a” relationship from a specialization to the generalization class. Common structure and behaviour are used from the specializtion to the generalized class. At a very broader level you can understand this as inheritance. Why I take the term inheritance is, you can relate this term very well. Generalization is also called a “Is-a” relationship. Example: Consider there exists a class named Person. A student is a person. A faculty is a person. Therefore here the relationship between student and person, similarly faculty and person is generalization. Realization Realization is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to realize the blueprint class. In other words, you can understand this as the relationship between the interface and the implementing class. Example: A particular model of a car ‘GTB Fiorano’ that implements the blueprint of a car realizes the abstraction. Dependency Change in structure or behaviour of a class affects the other related class, then there is a dependency between those two classes. It need not be the same vice-versa. When one class contains the other class it this happens. Example: Relationship between shape and circle is dependency.