抽象意味着隐藏“实现细节”.....所以抽象的目标是实现信息隐藏?如果没有实现细节,隐藏在信息隐藏中的是什么? 抽象是一种信息隐藏技术?
答案 0 :(得分:0)
抽象的目标不是隐藏变量值意义上的信息,而是封装。
抽象的唯一目标是允许程序员在不理解它的情况下使用算法或概念。信息隐藏可能是其中的副产品,但它不是它的目标。
答案 1 :(得分:0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* Example of Abstratcion: An application for mobile manufacturing company - Every phone must have to implement caller
* and sms feature but it depends on company to company (or model to model) if they want to include other features or not
* which are readily available , you just have to use it without knowing its implementation (like facebook in this example).
*/
namespace AbstractTest
{
public abstract class feature
{
public abstract void Caller();
public abstract void SMS();
public void facebook()
{
Console.WriteLine("You are using facebook");
}
}
public class Iphone : feature
{
public override void Caller()
{
Console.WriteLine("iPhone caller feature");
}
public override void SMS()
{
Console.WriteLine("iPhone sms feature");
}
public void otherFeature()
{
facebook();
}
}
public class Nokia : feature
{
public override void Caller()
{
Console.WriteLine("Nokia caller feature");
}
public override void SMS()
{
Console.WriteLine("Nokia sms feature");
}
}
class Program
{
static void Main(string[] args)
{
Iphone c1 = new Iphone();
c1.Caller();
c1.SMS();
c1.otherFeature();
Nokia n1 = new Nokia();
n1.Caller();
n1.SMS();
Console.ReadLine();
}
}
}